Brian Dunning's FileMaker Custom Functions

FormatDateTime ( dateValue ; timeValue ; format )

Returns the dateValue and/or timeValue formatted as specified in format, using PHP-like coding, and allowing for escaped non-formatted text.

  Average rating: 3.9 (51 votes) Log in to vote

Lewis Lorenz   Lewis Lorenz
Lorenz Companies
http://www.LorenzCom.com

Share on Facebook Share on Twitter

  Sample input:
FormatDateTime ( 9/21/2005 ; 11:06:53 ; "Y-m-d His \zulu\" )
FormatDateTime ( 10-3-2011 ; "" ; "\today is the \jS\ day\" )
  Sample output:
2005-09-21 110653 zulu
today is the 3rd day

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

FormatDateTime ( dateValue ; timeValue ; format )

by Lewis C. Lorenz
9/22/2011: Created
1/1/14: Modified

Returns the dateValue and/or timeValue formatted 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.
Escaped \ is written \\, all other escaped text must be enclosed within an opening \ and a closing \.
Formatting performed using PHP date() function format codes but with Filemaker conventions.

Passing '?' as the whole value of format returns this help text and the following code explanations.

Day -------
d - 01-31
D - Mon-Sun
j - 1-31
l (lowercase 'L') - Sunday-Saturday
N - 1 (Monday) ... 7 (Sunday). (PHP convention: ISO-8601 representation of day of week.)
S - st, nd, rd or th (English ordinal suffix.)
w - 1 (Sunday) ... 7 (Saturday). (PHP convention : 0 (for Sunday) through 6 (for Saturday).)
z - 1-366. (PHP convention: 0-365.)
Week -----
W - 1-54, week of year Jan. 1. (PHP convention: ISO-8601 week number of year, weeks starting on Monday.)
Month ----
F - January-December
m - 01-12
M - Jan-Dec
n - 1-12
t - 28-31
Year -----
L - Leap year (1/0)
o - year number. ISO-8601 year number.
Y - 4 digit year
y - 2 digit year
Time ----
a - am/pm
A - AM/PM
g - Hour 1-12
G - Hour 0-23
h - Hour 01-12
H - Hour 00-23
i - Min 00-59
s - Sec 00-59
u - Microseconds

NOTICE: This is a recursive function, so, if you change the function name remember to also change it in the function code.

Examples:
FormatDateTime ( 9/21/2005 ; 11:06:53 ; "Y-m-d His \zulu\" ) = 2005-09-21 110653 zulu
FormatDateTime ( 10-3-2011 ; "" ; "\today is the \jS\ day\" ) = today is the 3rd day

 

Comments

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Under construction. Email me your wish list for improvements.