Function overview
Prototype
php.date (
format; dateVal )
Parameters
format A string containing placeholders as described at http://php.net/manual/en/function.date.php
dateVal A date value to work with. If left blank, will use the current date
Description
Tags:
PHP Date PHP Format Date Format Date
Function Mimics the php date function. Very powerful date formatting function - should give you all info you ever need. http://php.net/manual/en/function.date.php for a list of possible place holders in the format tag.
Examples
Sample input
php.date( "D F jS H:iA"; "" ) & " and ... " & php.date("Y";"") & " is " & If( not php.date("L"; "" ) ; "not " ) & "a leap year"
Sample output
Tue November 11th 12:27PM and ... 2008 is a leap year
Function code
//See: http://php.net/manual/en/function.date.php
Let([
ts = If( IsEmpty(dateVal) ; Get(CurrentTimeStamp) ; GetAsTimestamp(dateVal) ) ;
d = GetAsDate(ts);
t = GetAsTime(ts);
tmpList = Substitute( format ;
["d";"|d|"];
["D";"|D|"];
["j";"|j|"];
["l";"|l|"];
["N";"|N|"];
["S";"|S|"];
["w";"|w|"];
["z";"|z|"];
["W";"|W|"];
["F";"|F|"];
["m";"|m|"];
["M";"|M|"];
["n";"|n|"];
["t";"|t|"];
["L";"|L|"];
["o";"|o|"];
["Y";"|Y|"];
["y";"|y|"];
["a";"|a|"];
["A";"|A|"];
["B";"|B|"];
["g";"|g|"];
["G";"|G|"];
["h";"|h|"];
["H";"|H|"];
["i";"|i|"];
["s";"|s|"];
["u";"|u|"]
)
];
Substitute( tmpList ;
/*** DAY ***/
["|d|";Right( "0" & Day (d) ; 2 )];
["|D|";Left( DayName(d) ; 3)];
["|j|";Day(d)];
["|l|";DayName(d)];
["|N|";If( DayOfWeek(d) = 1 ; 7 ; DayOfWeek(d) - 1 )];
["|S|";Case(
PatternCount( " 1 21 31 " ; " " & Day ( d ) & " ") ; TextStyleAdd("st";Superscript) ;
PatternCount( " 2 22 " ; " " & Day ( d ) & " ") ; TextStyleAdd("nd";Superscript) ;
PatternCount( " 3 23 " ; " " & Day ( d ) & " ") ; TextStyleAdd("rd";Superscript) ;
TextStyleAdd("th";Superscript)
) ];
["|w|";DayOfWeek(d) - 1];
["|z|";DayOfYear (d) - 1];
/*** WEEK ***/
["|W|";WeekOfYear ( d )];
/*** MONTH ***/
["|F|";MonthName(d)];
["|m|";Right( "0" & Month(d) ; 2 )];
["|M|";Left(MonthName(d);3)];
["|n|";Month(d)];
["|t|";Day(Date(Month(d);1;Year(d))-1)];
/*** YEAR ***/
["|L|";If( Day(Date( "2" ; "29" ; Year(d) )) = 1 ; 0 ; 1 )];
["|o|";Year(d)];
["|Y|";Year(d)];
["|y|";Right(Year(d);2)];
/*** TIME ***/
["|a|";If( Hour(t) > 11 ; "pm" ; "am" ) ];
["|A|";If( Hour(t) > 11 ; "PM" ; "AM" ) ];
["|g|";If( Hour(t) > 12 ; Hour(t) - 12 ; Hour(t)) ];
["|G|";Hour(t)];
["|h|";Right( "0" & If( Hour(t) > 12 ; Hour(t) - 12 ; Hour(t)) ; 2 ) ];
["|H|";Right( "0" & Hour(t) ; 2 ) ];
["|i|"; Right( "0" & Minute(t) ; 2) ];
["|s|"; Right( "0" & Seconds(t) ; 2 )]
)
)
// ===================================
/*
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/76
Prototype: php.date( format; dateVal )
Function Author: Genx (http://www.fmfunctions.com/mid/29)
Last updated: 31 January 2010
Version: 4.2
*/
// ===================================
//See: http://php.net/manual/en/function.date.php__LITBR____LITBR__Let([__LITBR__ ts = If( IsEmpty(dateVal) ; Get(CurrentTimeStamp) ; GetAsTimestamp(dateVal) ) ;__LITBR__ d = GetAsDate(ts);__LITBR__ t = GetAsTime(ts);__LITBR__ tmpList = Substitute( format ; __LITBR__ ["d";"|d|"];__LITBR__ ["D";"|D|"];__LITBR__ ["j";"|j|"];__LITBR__ ["l";"|l|"];__LITBR__ ["N";"|N|"];__LITBR__ ["S";"|S|"];__LITBR__ ["w";"|w|"];__LITBR__ ["z";"|z|"];__LITBR____LITBR__ ["W";"|W|"];__LITBR__ __LITBR__ ["F";"|F|"];__LITBR__ ["m";"|m|"];__LITBR__ ["M";"|M|"];__LITBR__ ["n";"|n|"];__LITBR__ ["t";"|t|"];__LITBR____LITBR__ ["L";"|L|"];__LITBR__ ["o";"|o|"];__LITBR__ ["Y";"|Y|"];__LITBR__ ["y";"|y|"];__LITBR____LITBR__ ["a";"|a|"];__LITBR__ ["A";"|A|"];__LITBR__ ["B";"|B|"];__LITBR__ ["g";"|g|"];__LITBR__ ["G";"|G|"];__LITBR__ ["h";"|h|"];__LITBR__ ["H";"|H|"];__LITBR__ ["i";"|i|"];__LITBR__ ["s";"|s|"];__LITBR__ ["u";"|u|"]__LITBR__ )__LITBR__];__LITBR__ Substitute( tmpList ; __LITBR__ /*** DAY ***/__LITBR__ ["|d|";Right( "0" & Day (d) ; 2 )];__LITBR__ ["|D|";Left( DayName(d) ; 3)];__LITBR__ ["|j|";Day(d)];__LITBR__ ["|l|";DayName(d)];__LITBR__ ["|N|";If( DayOfWeek(d) = 1 ; 7 ; DayOfWeek(d) - 1 )];__LITBR__ ["|S|";Case(__LITBR__ PatternCount( " 1 21 31 " ; " " & Day ( d ) & " ") ; TextStyleAdd("st";Superscript) ;__LITBR__ PatternCount( " 2 22 " ; " " & Day ( d ) & " ") ; TextStyleAdd("nd";Superscript) ;__LITBR__ PatternCount( " 3 23 " ; " " & Day ( d ) & " ") ; TextStyleAdd("rd";Superscript) ;__LITBR__ TextStyleAdd("th";Superscript)__LITBR__ ) ];__LITBR__ ["|w|";DayOfWeek(d) - 1];__LITBR__ ["|z|";DayOfYear (d) - 1];__LITBR____LITBR__ /*** WEEK ***/__LITBR__ ["|W|";WeekOfYear ( d )];__LITBR____LITBR__ /*** MONTH ***/__LITBR__ ["|F|";MonthName(d)];__LITBR__ ["|m|";Right( "0" & Month(d) ; 2 )];__LITBR__ ["|M|";Left(MonthName(d);3)];__LITBR__ ["|n|";Month(d)];__LITBR__ ["|t|";Day(Date(Month(d);1;Year(d))-1)];__LITBR____LITBR__ /*** YEAR ***/__LITBR__ ["|L|";If( Day(Date( "2" ; "29" ; Year(d) )) = 1 ; 0 ; 1 )];__LITBR__ ["|o|";Year(d)];__LITBR__ ["|Y|";Year(d)];__LITBR__ ["|y|";Right(Year(d);2)];__LITBR____LITBR__ /*** TIME ***/__LITBR__ ["|a|";If( Hour(t) > 11 ; "pm" ; "am" ) ];__LITBR__ ["|A|";If( Hour(t) > 11 ; "PM" ; "AM" ) ];__LITBR__ ["|g|";If( Hour(t) > 12 ; Hour(t) - 12 ; Hour(t)) ];__LITBR__ ["|G|";Hour(t)];__LITBR__ ["|h|";Right( "0" & If( Hour(t) > 12 ; Hour(t) - 12 ; Hour(t)) ; 2 ) ];__LITBR__ ["|H|";Right( "0" & Hour(t) ; 2 ) ];__LITBR__ ["|i|"; Right( "0" & Minute(t) ; 2) ];__LITBR__ ["|s|"; Right( "0" & Seconds(t) ; 2 )]__LITBR__ )__LITBR__)__LITBR____LITBR__// ===================================__LITBR__/*__LITBR____LITBR__ This function is published on FileMaker Custom Functions__LITBR__ to check for updates and provide feedback and bug reports__LITBR__ please visit http://www.fmfunctions.com/fid/76__LITBR____LITBR__ Prototype: php.date( format; dateVal )__LITBR__ Function Author: Genx (http://www.fmfunctions.com/mid/29)__LITBR__ Last updated: 31 January 2010__LITBR__ Version: 4.2__LITBR____LITBR__*/__LITBR__// ===================================
Login or register to comment
Create a new account with fmcustomfunctions.com or login to post a comment.