{"id":163,"date":"2011-12-02T20:07:14","date_gmt":"2011-12-02T20:07:14","guid":{"rendered":"http:\/\/www.lorenzcom.com\/?p=163"},"modified":"2020-12-03T07:30:51","modified_gmt":"2020-12-03T13:30:51","slug":"formatdatetime-datevalue-timevalue-format","status":"publish","type":"post","link":"https:\/\/lorenzcom.com\/?p=163","title":{"rendered":"FormatDateTime"},"content":{"rendered":"<h3>FormatDateTime ( dateValue , timeValue , format )<\/h3>\n<p>FormatDateTime formats FileMaker Pro date and time data using PHP Date formatting syntax. Returns a string of the dateValue and\/or timeValue as specified in format. If dateValue or timeValue are empty current date or current time are used. Optionally, use the backslash as an escape code to include text not intended to be formatted. This custom function formats the output using PHP Date function format codes but with FileMaker conventions.<\/p>\n<h4>Parameters<\/h4>\n<ul>\n<li>dateValue &#8211; If empty the current date is used.<\/li>\n<li>timeValue &#8211; If empty the current time is used.<\/li>\n<li>format &#8211; Specifies the content of the returned string. Optionally use the backslash as an escape code to include text not intended to be formatted.<\/li>\n<\/ul>\n<h4>Examples<\/h4>\n<ul>\n<li>FormatDateTime ( 10-31-2011, &#8220;&#8221;, &#8220;D., F j, Y&#8221;) = Mon., October 31, 2011<\/li>\n<li>FormatDateTime ( 10-31-2011, 8:46:21, &#8220;Y-m-d His \\zulu\\&#8221;) = 2011-10-31 084621 zulu<\/li>\n<li>FormatDateTime ( 10-3-2011, &#8220;&#8221;, &#8220;\\today is the \\jS\\ day\\&#8221;) = today is the 3rd day<\/li>\n<\/ul>\n<h4>HELP<\/h4>\n<p><strong><em>Passing &#8216;?&#8217; as the only text in format returns this help text with the following code explanations.<\/em><\/strong><\/p>\n<\/p>\n<p>Escaped \\ is written \\\\, all other escaped text must be enclosed within an opening \\ and a closing \\.<\/p>\n<p>Formatting performed using PHP Date function format syntax but with FileMaker Pro conventions.<\/p>\n<p><strong>Day &#8212;&#8212;-<\/strong><\/p>\n<ul>\n<li>d &#8211; 01-31<\/li>\n<li>D &#8211; Mon-Sun<\/li>\n<li>j &#8211; 1-31<\/li>\n<li>l (lowercase &#8216;L&#8217;) &#8211; Sunday-Saturday<\/li>\n<li>N &#8211; 1 (Monday) &#8230; 7 (Sunday). (PHP convention: ISO-8601 representation of day of week.)<\/li>\n<li>S &#8211; st, nd, rd or th (English ordinal suffix.)<\/li>\n<li>w &#8211; 1 (Sunday) &#8230; 7 (Saturday). (PHP convention : 0 (for Sunday) through 6 (for Saturday).)<\/li>\n<li>z &#8211; 1-366. (PHP convention: 0-365.)<\/li>\n<\/ul>\n<p><strong>Week &#8212;&#8211;<\/strong><\/p>\n<ul>\n<li>W &#8211; 1-54, week of year Jan. 1. (PHP convention: ISO-8601 week number of year, weeks starting on Monday.)<\/li>\n<\/ul>\n<p><strong>Month &#8212;-<\/strong><\/p>\n<ul>\n<li>F &#8211; January-December<\/li>\n<li>m &#8211; 01-12<\/li>\n<li>M &#8211; Jan-Dec<\/li>\n<li>n &#8211; 1-12<\/li>\n<li>t &#8211; 28-31<\/li>\n<\/ul>\n<p><strong>Year &#8212;&#8211;<\/strong><\/p>\n<ul>\n<li>L &#8211; Leap year (1\/0)<\/li>\n<li>o &#8211; year number. ISO-8601 year number.<\/li>\n<li>Y &#8211; 4 digit year<\/li>\n<li>y &#8211; 2 digit year<\/li>\n<\/ul>\n<p><strong>Time &#8212;-<\/strong><\/p>\n<ul>\n<li>a &#8211; am\/pm<\/li>\n<li>A &#8211; AM\/PM<\/li>\n<li>g &#8211; Hour 1-12<\/li>\n<li>G &#8211; Hour 0-23<\/li>\n<li>h &#8211; Hour 01-12<\/li>\n<li>H &#8211; Hour 00-23<\/li>\n<li>i &#8211; Min 00-59<\/li>\n<li>s &#8211; Sec 00-59<\/li>\n<li>u &#8211; Microseconds<\/li>\n<\/ul>\n<p><strong>NOTICE:<\/strong> This function is a recursive function. If you change the name of it, then change the name references inside the code.<\/p>\n<p><strong>FormatDateTime code:<\/strong> Copy the selected code below (click on Select All to highlight all the code) to the clipboard and paste it into a newly created Custom Function. <a href=\"\/docs\/FileMaker\/FormatDateTime.zip\">Download the code in a text file from here.<\/a><\/p>\n<form><textarea id=\"te_163\" style=\"width: 100%; height: 180px; font-family: Arial,Helvetica; font-size: .90em; line-height: normal;\">&lt;!&#8211;raw&#8211;&gt;Let( [d = If ( IsEmpty( dateValue ); Get ( CurrentDate ); GetAsDate ( dateValue ) );&lt;br \/&gt;<br \/>\nt = If ( IsEmpty( timeValue ); Get ( CurrentTime ); GetAsTime ( timeValue ) );&lt;br \/&gt;<br \/>\nformat = format &amp; If ( Mod ( PatternCount ( format; &#8220;\\\\&#8221; ); 2 ); &#8220;\\\\&#8221;; &#8220;&#8221; ); \/\/ Append \\ if count not even.&lt;br \/&gt;<br \/>\nf = Left ( format; 1 );&lt;br \/&gt;<br \/>\nf = If ( f = &#8220;\\\\&#8221;; Middle ( format; 1; Position ( format; &#8220;\\\\&#8221;; 2; 1 ) ); f ); \/\/ Escape found, set to full escaped string.&lt;br \/&gt;<br \/>\nc = Case(&lt;br \/&gt;<br \/>\nf = &#8220;\\\\\\\\&#8221;;  &#8220;\\\\&#8221;; \/\/ If a single blackslash has been escaped, make f a single backslash.&lt;br \/&gt;<br \/>\nLength ( f ) &gt; 1; Middle ( f; 2; Position ( f; &#8220;\\\\&#8221;; 2; 1 ) &#8211; 2); \/\/ Get the contents.&lt;br \/&gt;<br \/>\nExact ( f; &#8220;d&#8221; ) ; Right ( GetAsText ( 100 + Day ( d ) ); 2 ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;D&#8221; ) ; Left ( DayName ( d ) ; 3 ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;j&#8221; ) ; GetAsText ( Day ( d ) ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;l&#8221; ) ; DayName ( d ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;N&#8221; ) ; GetAsText ( If ( DayOfWeek ( d ) &#8211; 1 = 0; 7; DayOfWeek ( d ) &#8211; 1 ) ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;S&#8221; ) ; If ( PatternCount ( &#8220;11 12 13&#8221;; Right ( GetAsText ( 100 + Day ( d ) ); 2 ) ); &#8220;th&#8221;; Choose ( Mod ( Day ( d ) ; 10 ) ; &#8220;th&#8221;; &#8220;st&#8221;; &#8220;nd&#8221;; &#8220;rd&#8221;; &#8220;th&#8221;; &#8220;th&#8221;; &#8220;th&#8221;; &#8220;th&#8221;; &#8220;th&#8221;; &#8220;th&#8221; ) );&lt;br \/&gt;<br \/>\nExact ( f; &#8220;w&#8221; ) ; GetAsText ( DayOfWeek ( d ) ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;z&#8221; ) ; GetAsText ( DayOfYear ( d ) ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;W&#8221; ) ; GetAsText ( WeekOfYear ( d ) ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;F&#8221; ) ; MonthName ( d ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;m&#8221; ) ; Right ( GetAsText ( 100 + Month ( d ) ); 2 ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;M&#8221; ) ; Left ( MonthName ( d ) ; 3 ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;n&#8221; ) ; GetAsText ( Month ( d ) ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;t&#8221; ) ; GetAsText ( Day ( Date ( Month ( d ) + 1; 1; Year ( d ) ) &#8211; 1 ) ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;L&#8221; ) ; GetAsText ( If ( Day ( Date ( 3; 1; Year ( d ) ) &#8211; 1 ) = 29; 1; 0 ) ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;o&#8221; ) ; GetAsText ( Year ( d ) + Case ( WeekOfYear ( d ) = 1 and DayOfWeek ( Date ( 1; 1; Year ( d ) ) ) &gt; 1; -1; WeekOfYear ( d ) &gt; 52 and DayOfWeek ( Date ( 12; 31; Year ( d ) ) ) &lt; 7 ; 1 ; 0 ) ) ;<br \/>\nExact ( f; &#8220;Y&#8221; ) ; GetAsText ( Year ( d ) ) ;<br \/>\nExact ( f; &#8220;y&#8221; ) ; Right ( GetAsText ( Year ( d ) ) ; 2 ) ;<br \/>\nExact ( f; &#8220;a&#8221; ) ; If ( GetAsNumber ( t ) &gt; 43200; &#8220;pm&#8221;; &#8220;am&#8221; ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;A&#8221; ) ; If ( GetAsNumber ( t ) &gt; 43200; &#8220;PM&#8221;; &#8220;AM&#8221; ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;g&#8221; ) ; GetAsText ( If ( Hour ( t ) &gt; 12; Hour ( t ) &#8211; 12; Hour ( t ) ) ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;G&#8221; ) ; GetAsText ( Hour ( t ) ) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;h&#8221; ) ; Right ( GetAsText ( 100 + If ( Hour ( t ) &gt; 12; Hour ( t ) &#8211; 12; Hour ( t ) ) ); 2) ;&lt;br \/&gt;<br \/>\nExact ( f; &#8220;H&#8221; ) ; Right ( GetAsText ( 100 + Hour ( t ) ); 2 );&lt;br \/&gt;<br \/>\nExact ( f; &#8220;i&#8221; ) ; Right ( GetAsText ( 100 + Minute ( t ) ); 2);&lt;br \/&gt;<br \/>\nExact ( f; &#8220;s&#8221; ) ; Right ( GetAsText ( 100 + Seconds ( t ) ); 2);&lt;br \/&gt;<br \/>\nExact ( f; &#8220;u&#8221; ) ; GetAsText ( GetAsNumber ( t ) ) ;&lt;br \/&gt;<br \/>\nf);&lt;br \/&gt;<br \/>\n\/\/ Prepare for recursive call.&lt;br \/&gt;<br \/>\nformat = Right ( format; Length (format ) &#8211; Length ( f ) );&lt;br \/&gt;<br \/>\n\/\/ Prepare help text.&lt;br \/&gt;<br \/>\nh = If ( f = &#8220;?&#8221; and Length ( format ) = 0; &#8220;FormatDateTime ( dateValue, timeValue, format )\u00b6\u00b6Returns the dateValue and timeValue formatted as specified in format.\u00b6\u00b6If dateValue or timeValue are empty current date or current time are used.\u00b6Optionally use the backslash as an escape code to include text not intended to be formatted.\u00b6Escaped \\ is written \\\\\\, all other escaped text must be enclosed within an opening \\ and a closing \\.\u00b6Format codes are the same as PHP date() function format codes, but with Filemaker conventions.\u00b6\u00b6&lt;br \/&gt;<br \/>\nDay codes:\u00b6&lt;br \/&gt;<br \/>\nd &#8211;\t01-31\u00b6&lt;br \/&gt;<br \/>\nD &#8211;\tMon-Sun\u00b6&lt;br \/&gt;<br \/>\nj &#8211;\t1-31\u00b6&lt;br \/&gt;<br \/>\nl &#8211;\t (lowercase &#8216;L&#8217;) Sunday-Saturday\u00b6&lt;br \/&gt;<br \/>\nN &#8211;\t1 (Monday) &#8230; 7 (Sunday). (PHP convention: ISO-8601 representation of day of week.)\u00b6&lt;br \/&gt;<br \/>\nS &#8211;\tst, nd, rd or th (English ordinal suffix.)\u00b6&lt;br \/&gt;<br \/>\nw &#8211;\t1 (Sunday) &#8230; 7 (Saturday). (PHP convention : 0 (Sunday) &#8230; 6 (Saturday).)\u00b6&lt;br \/&gt;<br \/>\nz &#8211;\t1-366. (PHP convention: 0-365.)\u00b6\u00b6&lt;br \/&gt;<br \/>\nWeek codes:\u00b6&lt;br \/&gt;<br \/>\nW &#8211;\t1-54, week of year Jan. 1. (PHP convention: ISO-8601 week number of year, weeks starting on Monday.)\u00b6\u00b6&lt;br \/&gt;<br \/>\nMonth codes:\u00b6&lt;br \/&gt;<br \/>\nF &#8211;\tJanuary-December\u00b6&lt;br \/&gt;<br \/>\nm &#8211;\t01-12\u00b6&lt;br \/&gt;<br \/>\nM &#8211;\tJan-Dec\u00b6&lt;br \/&gt;<br \/>\nn &#8211;\t1-12\u00b6&lt;br \/&gt;<br \/>\nt &#8211;\t28-31\u00b6\u00b6&lt;br \/&gt;<br \/>\nYear codes:\u00b6&lt;br \/&gt;<br \/>\nL &#8211;\tLeap year (1\/0)\u00b6&lt;br \/&gt;<br \/>\no &#8211;\tyear number. ISO-8601 year number.\u00b6&lt;br \/&gt;<br \/>\nY &#8211;\t4 digit year\u00b6&lt;br \/&gt;<br \/>\ny &#8211;\t2 digit year\u00b6\u00b6&lt;br \/&gt;<br \/>\nTime codes:\u00b6&lt;br \/&gt;<br \/>\na &#8211; \tam\/pm\u00b6&lt;br \/&gt;<br \/>\nA &#8211;\tAM\/PM\u00b6&lt;br \/&gt;<br \/>\ng &#8211;\tHour: 1-12\u00b6&lt;br \/&gt;<br \/>\nG &#8211;\tHour: 0-23\u00b6&lt;br \/&gt;<br \/>\nh &#8211;\tHour: 01-12\u00b6&lt;br \/&gt;<br \/>\nH &#8211;\tHour: 00-23\u00b6&lt;br \/&gt;<br \/>\ni &#8211;\tMin: 00-59\u00b6&lt;br \/&gt;<br \/>\ns &#8211;\tSec: 00-59\u00b6&lt;br \/&gt;<br \/>\nu &#8211;\tMicroseconds\u00b6\u00b6&lt;br \/&gt;<br \/>\nExamples:\u00b6&lt;br \/&gt;<br \/>\nFormatDateTime ( 9\/21\/2005, 11:06:53, \\&#8221;Y-m-d His \\zulu\\\\\\&#8221;)  = 2005-09-21 110653 zulu\u00b6&lt;br \/&gt;<br \/>\nFormatDateTime ( 10-3-2011, \\&#8221;\\&#8221;, \\&#8221;\\today is the \\jS\\ day\\\\\\&#8221;)  = today is the 3rd day&lt;br \/&gt;<br \/>\n&#8220;; &#8220;&#8221; );&lt;br \/&gt;<br \/>\n\/\/ Recursive call if not empty.&lt;br \/&gt;<br \/>\nc = c &amp; If ( IsEmpty ( format ); &#8220;&#8221;; FormatDateTime ( d; t; format ) )];&lt;\/p&gt;<br \/>\n&lt;p&gt;If ( c = &#8220;?&#8221;; h; c ) \/\/ Send back just help text if format was a question mark (?).&lt;br \/&gt;<br \/>\n\/\/c&lt;\/p&gt;<br \/>\n&lt;p&gt;)&lt;\/p&gt;<br \/>\n&lt;p&gt;\/*&lt;br \/&gt;<br \/>\nFormatDateTime ( dateValue, timeValue, format )&lt;\/p&gt;<br \/>\n&lt;p&gt;by Lewis C. Lorenz&lt;\/p&gt;<br \/>\n&lt;p&gt;1-1-14 Updated&lt;\/p&gt;<br \/>\n&lt;p&gt;NOTICE: This is a recursive function. If you change the function name then also change it in the function code.&lt;\/p&gt;<br \/>\n&lt;p&gt;Returns the dateValue or timeValue formatted as specified in format.&lt;br \/&gt;<br \/>\nIf dateValue or timeValue are empty current date or current time are used.&lt;br \/&gt;<br \/>\nOptionally use the backslash as an escape code to include text not intended to be formatted.&lt;br \/&gt;<br \/>\nEscaped \\ is written \\\\, all other escaped text must be enclosed within an opening \\ and a closing \\.&lt;br \/&gt;<br \/>\nFormatting performed using PHP date() function format codes but with Filemaker conventions.&lt;\/p&gt;<br \/>\n&lt;p&gt;Passing &#8216;?&#8217; as the whole value of format returns this help text and the following code explanations.&lt;\/p&gt;<br \/>\n&lt;p&gt;Day &#8212;&#8212;-&lt;br \/&gt;<br \/>\nd &#8211;\t01-31&lt;br \/&gt;<br \/>\nD &#8211;\tMon-Sun&lt;br \/&gt;<br \/>\nj &#8211;\t1-31&lt;br \/&gt;<br \/>\nl (lowercase &#8216;L&#8217;) &#8211;\tSunday-Saturday&lt;br \/&gt;<br \/>\nN &#8211;\t1 (Monday) &#8230; 7 (Sunday). (PHP convention: ISO-8601 representation of day of week.)&lt;br \/&gt;<br \/>\nS &#8211;\tst, nd, rd or th (English ordinal suffix.)&lt;br \/&gt;<br \/>\nw &#8211;\t1 (Sunday) &#8230; 7 (Saturday). (PHP convention : 0 (for Sunday) through 6 (for Saturday).)&lt;br \/&gt;<br \/>\nz &#8211;\t1-366. (PHP convention: 0-365.)&lt;br \/&gt;<br \/>\nWeek &#8212;&#8211;&lt;br \/&gt;<br \/>\nW &#8211; 1-54, week of year Jan. 1. (PHP convention: ISO-8601 week number of year, weeks starting on Monday.)&lt;br \/&gt;<br \/>\nMonth &#8212;-&lt;br \/&gt;<br \/>\nF &#8211;\tJanuary-December&lt;br \/&gt;<br \/>\nm &#8211;\t01-12&lt;br \/&gt;<br \/>\nM &#8211;\tJan-Dec&lt;br \/&gt;<br \/>\nn &#8211;\t1-12&lt;br \/&gt;<br \/>\nt &#8211;\t28-31&lt;br \/&gt;<br \/>\nYear &#8212;&#8211;&lt;br \/&gt;<br \/>\nL &#8211;\tLeap year (1\/0)&lt;br \/&gt;<br \/>\no &#8211; year number. ISO-8601 year number.&lt;br \/&gt;<br \/>\nY &#8211;\t4 digit year&lt;br \/&gt;<br \/>\ny &#8211; 2 digit year&lt;br \/&gt;<br \/>\nTime &#8212;-&lt;br \/&gt;<br \/>\na &#8211; \tam\/pm&lt;br \/&gt;<br \/>\nA &#8211; AM\/PM&lt;br \/&gt;<br \/>\ng &#8211;\tHour 1-12&lt;br \/&gt;<br \/>\nG &#8211;\tHour 0-23&lt;br \/&gt;<br \/>\nh &#8211;\tHour 01-12&lt;br \/&gt;<br \/>\nH &#8211;\tHour 00-23&lt;br \/&gt;<br \/>\ni &#8211;\tMin 00-59&lt;br \/&gt;<br \/>\ns &#8211;\tSec 00-59&lt;br \/&gt;<br \/>\nu &#8211;\tMicroseconds&lt;\/p&gt;<br \/>\n&lt;p&gt;Examples:&lt;br \/&gt;<br \/>\nFormatDateTime ( 9\/21\/2005, 11:06:53, &#8220;Y-m-d His \\zulu\\&#8221;)  = 2005-09-21 110653 zulu&lt;br \/&gt;<br \/>\nFormatDateTime ( 10-3-2011, &#8220;&#8221;, &#8220;\\today is the \\jS\\ day\\&#8221;)  = today is the 3rd day&lt;br \/&gt;<br \/>\n*\/&lt;!&#8211;\/raw&#8211;&gt;<\/textarea><br \/>\n<input type=\"button\" value=\"Select All\" \/> <input type=\"reset\" value=\"Reset\" \/><\/form><\/p>\n","protected":false},"excerpt":{"rendered":"<p>FormatDateTime ( dateValue , timeValue , format ) FormatDateTime formats FileMaker Pro date and time data using PHP Date formatting syntax. Returns a string of the dateValue and\/or timeValue as specified in format. If dateValue or timeValue are empty current <span class=\"excerpt-dots\">&hellip;<\/span> <a class=\"more-link\" href=\"https:\/\/lorenzcom.com\/?p=163\"><span class=\"more-msg\">Continue reading &rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10,15,14],"tags":[37,18,36,17,19],"_links":{"self":[{"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/posts\/163"}],"collection":[{"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=163"}],"version-history":[{"count":40,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/posts\/163\/revisions"}],"predecessor-version":[{"id":879,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/posts\/163\/revisions\/879"}],"wp:attachment":[{"href":"https:\/\/lorenzcom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}