php.date ( )

Function stats

Average user rating
29
76
9999
Support
FileMaker 8.5 +
Date posted
17 November 2008
Last updated
31 January 2010
Version
Recursive function
No

Author Info
 Genx

18 functions

Average Rating 4.1

author_avatar



 

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

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

 

Comments


06 September 2010



Brilliant CF, Genx. Nicely formated too, so it makes it easier to understand its mechanics. Thanks for sharing.
  General comment

 

 


Login or register to comment

Create a new account with fmcustomfunctions.com or login to post a comment.

 

 

 

Top Tags

Text Parsing  (31)
List  (20)
XML  (20)
Date  (19)
Format  (18)
Debug  (12)
Dev  (11)
Variables  (11)
Layout  (11)
Interface  (10)
Text  (10)
Filter  (10)
ValueIterator  (6)
Layout Objects  (6)
Uuid  (6)
HTML  (6)