I've been referencing the MSDN articles a lot recently on Date and Time format strings and sometimes I get confused by the many options and sometimes these formats do not carry over or function. So I wanted to build a quick reference sheet that I can refer to in my workflows and forms.
First, how to use the inline and runtime functions.
Represents a date time value in text of a specific format.
fn-FormatDate({WorkflowVariable:MyDate}, d)
Other Notes
fn-FormatDate({WorkflowVariable:MyDate}, "dd/MM/yyyy") and fn-FormatDate({WorkflowVariable:MyDate}, dd/MM/yyyy) both produce 11/08/2015
fn-FormatDate({WorkflowVariable:MyDate}, "D") and fn-FormatDate({WorkflowVariable:MyDate}, D) both produce Tuesday, August 11, 2015
For Time intervals, I found that using a single h, to provide the non-leading zero hour does not work and results in an error. But if you use the special format character % you can get the result of a non-leading zero hour digit. For exmaple: fn-FormatDate({WorkflowVariable:MyDate}, %h) returns 8, while fn-FormatDate({WorkflowVariable:MyDate}, hh) returns 08.
Returns the date in the specified format.
formatDate(date, format) or formateDate({namedControl}, "D")
Other Notes
The specified format can incorporate structures such as "dd/MM/yyyy" or "dddd", "dd MMM". Alternatively, single character format specifiers can be used. The components of these structures include:
Element Description Example (in US date format)
Format Specifier | Description | Examples | Result |
"dd" | Day of month (double digit) 3/1/2017 | fn-FormatDate({CurrentDate}, "dd") | 01 |
"ddd" | Day of week (Abbreviated) 3/1/2017 | fn-FormatDate({CurrentDate}, "ddd") | Wed or W (see notes) |
"dddd" | Day of week (Full) 3/1/2017 | fn-FormatDate({CurrentDate}, "dddd") | Wednesday |
"MM" | Month (Numeric) 3/1/2017 | fn-FormatDate({CurrentDate}, "MM") | 03 |
"MMM" | Month (Short) 3/1/2017 | fn-FormatDate({CurrentDate}, "MMM") | Mar |
"MMMM" | Month (Full) 3/1/2017 | fn-FormatDate({CurrentDate}, "MMMM") | March |
"yyyy" | Year 3/1/2017 1:45:30 PM | fn-FormatDate({CurrentDate}, "yyyy") | 2017 |
"%h" | Hours (12 Hour) 3/1/2017 1:45:30 PM | fn-FormatDate({CurrentDate}, "%h") | 1 |
"hh" | Hours (12 Hour) 3/1/2017 1:45:30 PM | fn-FormatDate({CurrentDate}, "hh") | 01 in WF, but 1 in Forms |
"HH" | Hours (24 hour) 3/1/2017 1:45:30 PM | fn-FormatDate({CurrentDate}, "HH") | 13 |
"mm" | Minutes 3/1/2017 1:45:30 PM | fn-FormatDate({CurrentDate}, "mm") | 45 |
"tt" | AM or PM 3/1/2017 1:45:30 PM | fn-FormatDate({CurrentDate}, "tt") | PM |
"d" | Short date pattern 3/1/2017 | fn-FormatDate({CurrentDate}, "d") | 3/1/2017 |
"D" | Long date pattern 3/1/2017 | fn-FormatDate({CurrentDate}, "D") | Wednesday, March 1, 2017 |
"M", "m" | Month/day pattern 3/1/2017 | fn-FormatDate({CurrentDate}, "M") | March 1 |
"s" | Sortable date/time pattern 6/15/2009 1:45:30 PM | fn-FormatDate({CurrentDate}, "s") | 2009-06-15T13:45:30 |
"t" | Short time 3/1/2017 1:45:30 PM | fn-FormatDate({CurrentDate}, "t") | 1:45PM |
"T" | Long time 3/1/2017 1:45:30 PM | fn-FormatDate({CurrentDate}, "T") | 1:45:30PM |
"Y", "y" | Year month 3/1/2017 1:45:30 PM | fn-FormatDate({CurrentDate}, "Y") | March 2017 |
"M/d/y" | Short Date pattern 3/1/2017 | fn-FormatDate({CurrentDate}, "M/d/y") | 3/1/17 |
"d/M/y" | Short Date pattern 3/1/2017 | fn-FormatDate({CurrentDate}, "d/M/y") | 1/3/17 |
"MM/dd/yyyy" | Short Date with leading zero Day and Month | fn-FormatDate({CurrentDate}, "MM/dd/yyyy") | 03/01/2017 |
"M/dd/yyyy" | Short Date with leading zero Day | fn-FormatDate({CurrentDate}, "M/dd/yyyy") | 3/01/2017 |
"MM/d/yyyy" | Short Date with leading zero Month | fn-FormatDate({CurrentDate}, "MM/d/yyyy") | 03/1/2017 |
NOTES:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.