date.translate ( )

Function stats

Average user rating
37
316
9999
Support
FileMaker 8.0 +
Date posted
03 September 2011
Last updated
08 May 2015
Version
Recursive function
No

Author Info
 Fabrice

74 functions

Average Rating 4.4

author_avatar



 

Function overview

Prototype

date.translate  ( _date;   _pattern;   _lang )


Parameters

_date  


_pattern  


_lang  


Description

Tags:  Localisation   Format Date   Format   Date  

Formats and translates date according to a pattern in one of the supported languages.

    _date a field or value containing a date
    _pattern - a string like "DDDD, MMMM D YYYY"
    _lang - a string containing the Language ID
        currently supported:
        "nl" -> Dutch
        "en" -> English
        "de" -> German
        "fr" -> French
        "es" -> Spanish
        "it" -> Italian
        "fu" -> Friulan
        "ka" -> Kabylian
        "hr" -> Coratian
        "ro" -> Romanian
        "ru" -> Russian
        "ua" -> Ukrainian
        "sl" -> Slovene
        "mk" -> Macedonian
        "sr" -> Serbian
        "me" -> Montenegrin
        "bg" -> Bulgarian
        "sq" -> Albanian
        "ba" -> Bosnian

    _pattern can take the following arguments:
        "YYYY"    4 digit year
        "YYY"    same as "YYYY"
        "YY"    2 digit year
        "Y"        1 digit year
        "MMMM"    Full month name
        "MMM"    Short month name
        "MM"    2 digit month (leading 0)
        "M"        1 or 2 digit month
        "DDDD"    Full weekday name
        "DDD"    Short weekday name
        "DD"    2 digit daynumber (leading 0)
        "D"        1 or 2 digit daynumber
        "S"        a day suffix such as 1st, 2nd, 3rd, 4th (English), or 1er (French)...

    Typical pattern for English long dates: MMMM DS YYYY
    for French long dates : DS MMMM YYYY


Return type: Text

Examples

Sample input

date.translate ( 1/1/2010 ; "MMMM DS YYYY" ; "en" )
date.translate ( 1/1/2010 ; "DS MMMM YYYY" ; "fr" )
date.translate ( 1/1/2010 ; "DS MMMM YYYY" ; "ru" )


Sample output

January 1st 2010
1er Janvier 2010
1го Январь 2010

 

Function code

/*
date.translate ( _date ; _pattern ; _lang )
v2.2


by Fabrice Nordmann, 1-more-thing
www.1-more-thing.com
www.twitter.com/1morethingTweet

based on a function by The Ros

====== version history ========

v2.2 - Even more languages
v2.1 - More languages
v2 - Jan 2007
DayNameList () and MonthNamesList () are now included in this function

v2.1 - Apr 2007
Corrected a bug for monthes starting with a M
Added the suffix parameter in the string (S) so DS returns 25th if language is "en"
Added support of Italian (thanks to Thierry Riva)
Added support of Friulan (thanks to Ugo di Luca)
Added support of Kabylian ( thanks to Amar Kenouche)
======

Formats a date according to a Format string and a given language ID:

    _date a field or value containing a date
    _pattern - a string like "DDDD, MMMM D YYYY"
    _lang - a string containing the Language ID
        currently supported:
        "nl" -> Dutch
        "en" -> English
        "de" -> German
        "fr" -> French
        "es" -> Spanish
        "it" -> Italian
        "fu" -> Friulan
        "ka" -> Kabylian
        "hr" -> Coratian
        "ro" -> Romanian
        "ru" -> Russian
        "ua" -> Ukrainian
        "sl" -> Slovene
        "mk" -> Macedonian
        "sr" -> Serbian
        "me" -> Montenegrin
        "bg" -> Bulgarian
        "sq" -> Albanian
        "ba" -> Bosnian

    _pattern can take the following arguments:
        "YYYY"    4 digit year
        "YYY"    same as "YYYY"
        "YY"    2 digit year
        "Y"        1 digit year
        "MMMM"    Full month name
        "MMM"    Short month name
        "MM"    2 digit month (leading 0)
        "M"        1 or 2 digit month
        "DDDD"    Full weekday name
        "DDD"    Short weekday name
        "DD"    2 digit daynumber (leading 0)
        "D"        1 or 2 digit daynumber
        "S"        a day suffix such as 1st, 2nd, 3rd, 4th (English), or 1er (French)...

Return type: Text

date.translate ( Date ( 7 ; 9 ; 2005 ) ; "DDDD, D MMMM YYYY" , "nl" )
    -> returns "zaterdag, 9 juli 2005"

If the _lang parameter is empty, the application language is used.
------------------------------------------------------------------------------- */
Case ( IsEmpty ( _date ) ; "" ;
Let ([
    _lg = Case ( not IsEmpty ( _lang ) ; _lang ; Get ( ApplicationLanguage )) ;
    _lg = Left ( Lower ( Trim ( _lg ) ) ; 2 ) ;

//======================= DAY LIST ========================
    _daylist =
        Case (
            _lg = "nl" ;    // Dutch
                "zondag¶maandag¶dinsdag¶woensdag¶donderdag¶vrijdag¶zaterdag¶zo¶ma¶di¶wo¶do¶vr¶za" ;
            
            _lg = "en" ;    // English
                "Sunday¶Monday¶Tuesday¶Wednesday¶Thursday¶Friday¶Saturday¶Sun¶Mon¶Tue¶Wed¶Thu¶Fri¶Sat" ;
            
            _lg = "de" ;    // German
                "Sonntag¶Montag¶Dienstag¶Mittwoch¶Donnerstag¶Freitag¶Samstag¶Son¶Mon¶Die¶Mit¶Don¶Fre¶Sam" ;
            
            _lg = "fr" ;    // French
                "dimanche¶lundi¶mardi¶mercredi¶jeudi¶vendredi¶samedi¶dim¶lun¶mar¶mer¶jeu¶ven¶sam" ;
            
            _lg = "es" ;    // Spanish
                "domingo¶lunes¶martes¶miércoles¶jueves¶viernes¶sábado¶do¶lu¶ma¶mi¶ju¶vi¶sa";
            
            _lg = "it" ;    // Italian
                "Domenica¶Lunedì¶Martedì¶Mercoledì¶Giovedì¶Venerdì¶Sabato¶Do¶Lu¶Ma¶Me¶Gi¶Ve¶Sa" ;
            
            _lg = "fu" ;    // Friulan
                "domenie¶lunes¶martas¶miercus¶joibe¶vinars¶sâbide¶do¶lu¶ma¶mi¶jo¶vi¶sâ" ;
            
            _lg = "ka" ;    // Kabylian
                "Acer¶Arim¶Aram¶Ahad¶Amhad¶Sem¶Sed¶Ac¶Ai¶Aa¶Ah¶Am¶Sm¶Sd" ;
            
            _lg = "hr" ;    // Croatian
                "Nedjelja¶Ponedjeljak¶Utorak¶Srijeda¶Četvrtak¶Petak¶Subota¶Ned¶Pon¶Uto¶Sri¶Čet¶Pet¶Sub" ;
            
            _lg = "ro" ;    // Romanian
                "Duminică¶Luni¶Marți¶Miercuri¶Joi¶Vineri¶Sâmbătă¶Dum¶Lun¶Mar¶Mie¶Joi¶Vin¶Sâm" ;
            
            _lg = "me" ;    // Montenegrin
                "nedjelja¶ponedjeljak¶utorak¶srijeda¶četvrtak¶petak¶subota" & "¶ned¶pon¶uto¶sri¶čet¶pet¶sub" ;

            _lg = "sl" ;    // Slovene
                "Nedelja¶Ponedeljek¶Torek¶Sreda¶Četrtek¶Petek¶Sobota¶Nedelja" & "¶Ne¶Po¶To¶Sr¶Če¶Pe¶So " ;
            
            _lg = "sq" ;    // Albanian
                "E Djelë¶E Hënë¶E Martë¶E Mërkurë¶E Enjte¶E Premte¶E Shtunë¶" & "E Djelë¶E Hënë¶E Martë¶E Mërkurë¶E Enjte¶E Premte¶E Shtunë" ; // no short form
            
            _lg = "mk" ;    // Macedonian
                "Недела¶Понеделник¶Вторник¶Среда¶Четврток¶Петок¶Сабота¶Нед¶Пон¶Вто¶Сре¶Чет¶Пет¶Саб" ;
            
            _lg = "bg" ;    // Bulgarian
                "Неделя¶Понеделник¶Вторник¶Сряда¶Четвъртък¶Петък¶Събота; Нед¶Пон.¶Вто¶Сря¶Чет¶Пет¶Съб" ;
            
            _lg = "ba" ;    // Bosnian
                "Nedjelja¶Ponedjeljak¶Utorak¶Srijeda¶Četvrtak¶Petak¶Subota¶Ned¶Pon¶Uto¶Sri¶Čet¶Pet¶Sub" ;
            
            _lg = "sr" or _lg = "rs" ;    // Serbian
                "nedelja¶ponedeljak¶utorak¶sreda¶četvrtak¶petak¶subota¶" & "ned¶pon¶uto¶sre¶čet¶pet¶sub" ;
            
            _lg = "ua" ;    // Ukrainian
                "Неділя¶Понеділок¶Вівторок¶Середа¶Четвер¶П’ятниця¶Субота¶" & "Неділя¶Понеділок¶Вівторок¶Середа¶Четвер¶П’ятниця¶Субота" ; // no short form
            
            _lg = "ru" ;    // Russian
                "Воскресенье¶Понедельник¶Вторник¶Среда¶Четверг¶Пятница¶Суббота¶" & "Воскресенье¶Понедельник¶Вторник¶Среда¶Четверг¶Пятница¶Суббота" ; // no short form

        "") ;

//======================= MONTHLIST ========================
    _monthlist =

        Case (
            _lg = "nl" ;    // Dutch
                "januari¶februari¶maart¶april¶mei¶juni¶juli¶augustus¶september¶oktober¶november¶december¶" &
                "jan¶feb¶mrt¶apr¶mei¶jun¶jul¶aug¶sept¶okt¶nov¶dec" ;

            _lg = "en" ;    // English
                "January¶February¶March¶April¶May¶June¶July¶August¶September¶October¶November¶December¶" &
                "Jan¶Feb¶Mar¶Apr¶May¶Jun¶Jul¶Aug¶Sept¶Oct¶Nov¶Dec" ;

            _lg = "de" ;    // German
                "Januar¶Februar¶März¶April¶Mai¶Juni¶Juli¶August¶September¶Oktober¶November¶Dezember¶" &
                "Jan¶Feb¶Mrz¶Apr¶Mai¶Jun¶Jul¶Aug¶Sept¶Okt¶Nov¶Dez" ;

            _lg = "fr" ;    // French
                "janvier¶février¶mars¶avril¶mai¶juin¶juillet¶août¶septembre¶octobre¶novembre¶décembre¶" &
                "jan¶fév¶mar¶avr¶mai¶juin¶juil¶août¶sept¶oct¶nov¶déc" ;

            _lg = "es" ;    // Spanish
                "enero¶febrero¶marzo¶abril¶mayo¶junio¶julio¶agosto¶septiembre¶octubre¶noviembre¶diciembre¶" &
                "ene¶feb¶mar¶abr¶may¶jun¶jul¶ago¶sept¶oct¶nov¶dic" ;

            _lg = "it" ;    // Italian
                "gennaio¶febbraio¶marzo¶aprile¶maggio¶giugno¶luglio¶agosto¶settembre¶ottobre¶novembre¶dicembre¶" &
                "gen¶feb¶mar¶apr¶mag¶giu¶lug¶ago¶set¶ott¶nov¶dic" ;

            _lg = "fu" ;    // Friulan
            "genâr¶fevrar¶marč¶avrîl¶mai¶jugn¶lui¶avost¶setembar¶otubar¶novembar¶decembar¶" &
            "gen¶fev¶mar¶avr¶mai¶jug¶lui¶avo¶set¶otu¶nov¶dec" ;

            _lg = "ka" ;    // Kabylian
                "Yennayer¶Furar¶Maghres¶Yebrir¶Maggumai¶Yunyu¶Yulyu¶Ghuscht¶Cutembir¶Thuver¶Wambir¶Dujembir" &
                "Yen¶Fur¶Mar¶Yeb¶Mag¶Yun¶Yul¶Ghu¶Cut¶Wam¶Duj" ;

            _lg = "hr" ;    // Croatian
                "Siječanj¶Veljača¶Ožujak¶Travanj¶Svibanj¶Lipanj¶Srpanj¶Kolovoz¶Rujan¶Listopad¶Studeni¶Prosinac¶" &
                "Sij¶Velj¶Ožu¶Tra¶Svi¶Lip¶Srp¶Kol¶Ruj¶Lis¶Stu¶Pro" ;

            _lg = "ro" ;    // Romanian
                "Ianuarie¶Februarie¶Martie¶Aprilie¶Mai¶Iunie¶Iulie¶August¶Septembrie¶Octombrie¶Noiembrie¶Decembrie¶" &
                "Ian¶Feb¶Mar¶Apr¶Mai¶Iun¶Iul¶Aug¶Sept¶Oct¶Nov¶Dec" ;

            _lg = "me" ;    // Montenegrin
                "januar¶februar¶mart¶april¶maj¶jun¶jul¶avgust¶septembar¶oktobar¶novembar¶decembar¶" &
                "jan¶feb¶mar¶apr¶maj¶jun¶jul¶avg¶sept¶okt¶nov¶dec" ;

            _lg = "sl" ;    // Slovene
                "Januar¶Februar¶Marec¶April¶Maj¶Junij¶Julij¶Avgust¶September¶Oktober¶November¶December¶" &
                "Jan¶Feb¶Mar¶Apr¶Maj¶Jun¶Jul¶Avg¶Sept¶Okt¶Nov¶Dec" ;

            _lg = "sq" ;    // Albanian
                "Janar¶Shkurt¶Mars¶Prill¶Maj¶Qershor¶Korrik¶Gusht¶Shtator¶Tetor¶Nentor¶Djetor¶" &
                "Jan¶Shk¶Mars¶Pri¶Maj¶Qer¶Korr¶Gush¶Shtat¶Tet¶Nent¶Dhjet" ;

            _lg = "mk" ;    // Macedonian
                "Јануари¶Фебруари¶Март¶Април¶Мај¶Јуни¶Јули¶Август¶Септември¶Октомври¶Ноември¶Декември¶" &
                "Јан¶Феб¶Мар¶Апр¶Мај¶Јун¶Јул¶Авг¶Сеп¶Окт¶Ное¶Дек" ;

            _lg = "bg" ;    // Bulgarian
                "Януари¶Февруари¶Март¶Април¶Май¶Юни¶Юли¶Август¶Септември¶Октомври¶Ноември¶Декември¶" &
                "Яну¶Фев¶Мар¶Апр¶Юни¶Юли¶Авг¶Сеп¶Окт¶Ное¶Дек" ;

            _lg = "ba" ;    // Bosnian
                "Siječanj¶Veljača¶Ožujak¶Travanj¶Svibanj¶Lipanj¶Srpanj¶Kolovoz¶Rujan¶Listopad¶Studeni¶Prosina¶" &
                "Sij¶Velj¶Ožu¶Tra¶Svi¶Lip¶Srp¶Kol¶Ruj¶Lis¶Stu¶Pro" ;

            _lg = "sr" or _lg = "rs" ;    // Serbian
                "januar¶februar¶mart¶april¶maj¶jun¶jul¶avgust¶septembar¶oktobar¶novembar¶decembar¶" &
                "jan¶feb¶mar¶apr¶maj¶jun¶jul¶avg¶sep¶okt¶nov¶dec" ;

            _lg = "ua" ;    // Ukrainian
                "Січень¶Лютий¶Березень¶Квітень¶Травень¶Червень¶Липень¶Серпень¶Вересень¶Жовтень¶Листопад¶Грудень¶" &
                "СІЧ¶ЛЮТ¶БЕР¶КВІ¶ТРА¶ЧЕР¶ЛИП¶СЕР¶ВЕР¶ЖОВ¶ЛИС¶ГРУ" ;

            _lg = "ru" ;    // Russian
                "Январь¶Февраль¶Март¶Апрель¶Май¶Июнь¶Июль¶Август¶Сентябрь¶Октябрь¶Ноябрь¶Декабрь¶" &
                "ЯНВ¶ФЕВР¶МАРТ¶АПР¶МАЙ¶ИЮНЬ¶ИЮЛЬ¶АВГ¶СЕНТ¶ОКТ¶НОЯБ¶ДЕК" ;

        "") ;
//======================= SUFFIX ========================
    _d = Day ( _date ) ;
    _dend = Right ( _d ; 1 ) ;
    _suffix = Case (

        _lg = "en" ;    // English
            Case ( _dend = 1 and _d <> 11 ; "st" ; _dend = 2 and _d <> 12 ; "nd" ; _dend = 3 and _d <> 13 ; "rd" ; "th" ) ;

        _lg = "fr" ;    // French
            Case ( _d = 1 ; "er" ; "" ) ;

        _lg = "hr" ;    // Croatian
            Case ( _dend = 1 ; "-vi" ; _dend = 2 ; "-gi" ; _dend = 3 ; "-ći" ; _dend = 4 ; "-ti" ; _dend = 5 ; "-ti" ; _dend = 6 ; "-ti" ; "-itd" ) ;

        _lg = "sl" ;    // Slovene
            "i" ;

        _lg = "mk" ;    // Macedonian
            Case ( _dend = 1 ; "ви" ; _dend = 2 ; "ри" ; _dend = 7 or _dend = 8 ; "ми" ; "ти" ) ;

        _lg = "bg" ;    // Bulgarian
            Case ( _dend = 1 ; "ви" ; _dend = 2 ; "ри" ; _dend = 7 or _dend = 8 ; "ми" ; "ти" ) ;

        _lg = "ba" ;    // Bosnian
            "." ;

        _lg = "ua" ;    // Ukrainian
            "го" ;

        _lg = "ru" ;    // Russian
            "го" ;

        "" ) ;

    _dte = GetAsDate ( _date ) ;
    _dow = DayOfWeek ( _dte ) ;
    _m = Month ( _dte ) ;
    _y = Year ( _dte ) ;
    _str = Substitute ( Upper ( _pattern ) ; ["Y" ; "^" ] ; [ "M" ; "°" ] ; [ "D" ; "²" ] ; [ "S" ; "ƒ" ])
] ;
Substitute ( _str ;
[ "^^^^"    ; _y ] ;
[ "^^^"        ; _y ] ;
[ "^^"        ; Right ( "00" & Mod ( _y ; 100 ) ; 2 ) ] ;
[ "^"        ; Right ( _y ; 1 ) ] ;
[ "²²²²"        ; GetValue ( _daylist ; _dow ) ] ;
[ "²²²"        ; GetValue ( _daylist ; _dow + 7 ) ] ;
[ "²²"        ; Right ( "00" & Day ( _dte ) ; 2 ) ] ;
[ "²"        ; Day ( _dte ) ] ;
[ "°°°°"    ;    GetValue ( _monthlist ; _m ) ] ;
[ "°°°"        ; GetValue ( _monthlist ; _m + 12 ) ] ;
[ "°°"        ; Right ( "00" & _m ; 2 ) ] ;
[ "°"        ; _m ] ;
[ "ƒ"        ; _suffix ]
)
)
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/316

    Prototype: date.translate( _date; _pattern; _lang )
    Function Author: Fabrice (http://www.fmfunctions.com/mid/37)
    Last updated: 08 May 2015
    Version: 1.3

*/
// ===================================

 

 

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (31)
Date  (28)
XML  (26)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Interface  (15)
Layout  (15)
Text  (14)
Variables  (12)
Layout Objects  (11)
Filter  (11)
Design  (10)
Array  (7)