cancel
Showing results for 
Search instead for 
Did you mean: 

Date and Time Format Strings - Quick Reference Guide

andrewg
Nintex Newbie
54 33 70.9K

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.

fn-FormatDate in Workflows

Represents a date time value in text of a specific format.

Usage

fn-FormatDate({WorkflowVariable:MyDate}, d)

Other Notes

  • For workflow inline functions, using single quotes takes the value as a literal. So for the formateDate function fn-FormatDate({WorkflowVariable:MyDate}, 'D') provides the value of D.
  • Using double quotes or no quotes produces the same result. For example:

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

  • If you attempt to calculate for a time format, but the value provided is date ONLY, then the function will result in an error.

Time Calculations

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.

formatDate on Forms

Returns the date in the specified format.

Usage

formatDate(date, format) or formateDate({namedControl}, "D")

Other Notes

  • In the format string, using single or double quotes is required. Using no quotes results in an error.

Table of Date and Time Format Strings

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:

  • dd - will provide a two digit days, so the first of the month will be 01
  • MM - will provide a two digit month, so March will be seen as 03. Using a single M will be just 3, a single digit. Notice that capital M is month and lowercase m is minutes.
  • d - can be used in two different ways. "d" by itself provides a short date pattern 3/1/2017, while using d in a date pattern like "M/d/y" will provide 3/1/17. Notice it is a single digit day when appropriate.
  • y - can be used in two different ways. "y" by itself provides a Year Month pattern of March 2017. But using "y" in a date pattern like "M/d/y" will provide 3/1/17. Notice the year is only the last two digits.
  • Using "ddd" provides an abbreviation of the day name. But it was found to react differently based on platform and local
    • On Prem: return W in English, other locals produce a 2 or 3 character response as appropriate. As Marian Hatala‌ noted, the value of day name abbrv is taken from Sys.CultureInfo.CurrentCulture.dateTimeFormat.ShortestDayNames
    • O365: returns Wed
33 Comments
njlech
Nintex Newbie

This is an excellent resource.  Thank you Andrew!

melissac
Nintex Newbie

Awesome!!!!

Thanks this is GREAT! @Andrew Glasser

cassymfreeman
Nintex Newbie

excellent - Josh Shutts​ this might come in handy for you

shuttjo
Nintex Newbie

Very cool! Thanks for thinking of me!

ramchhina
Nintex Newbie

Great resource. Thank you Andrew.

rickbakker
Nintex Newbie

Hi ‌,

Just for the record: When I use the 'ddd' option, I get a double letter returned (ma, di, ...). My locale is Dutch.

Cheers,

Rick

andrewg
Nintex Newbie

I just updated the format table with usage examples as well as some additional usages. Please see the new NOTES section at the bottom for additional tips. 

cassymfreeman
Nintex Newbie

Hey

we were testing our most recent upgrade of forms and looking at these. Tried "ddd" and it didn't work. Went to our previous version and it didn't work. Support have said it has never worked. Thought I'd let you know

andrewg
Nintex Newbie

FormatDate({CurrentDate}, "ddd") works in Nintex Forms in O365 for sure! What version didn't work for you? There could be a limitation somewhere i'm sure. 

emha
Nintex Newbie

for me it works as well - tested on NF2013  2.7.0.0 and 2.10.0.0

with just slight difference to the table above that day abbrv for english locale is returned as single character (first letter).

for other locales it returns 2 or 3 characters long abbrv.

the value of day name abbrv it taken from Sys.CultureInfo.CurrentCulture.dateTimeFormat.ShortestDayNames

cassymfreeman
Nintex Newbie

On prem the latest version (can't remember numbers right now). Yes does what Marian says and just gives me the first letter. I can get first letter or full day, just not abbreviation. Anyway, support are investigating I'll keep you posted  

andrewg
Nintex Newbie

Ok, that makes sense then. My testing on prem when I wrote the first article had just the first letter also. That msut have been the reason. When I tested them all again this time, I did it in O365 and go the three letters. 

I agree with you, the on prem other locals provide 2 or 3, but English is single character. 

Great work team in finding out the details! Not sure what the expected behavior is as they were not documented before. So each version and local may be working as planned, just not consistent. 

andrewg
Nintex Newbie

Thanks guys, I updated the table and notes to include your findings as to call it out quickly to others. Your contributions are much appreciated!

burkslm
Nintex Newbie

Dates can be a pain sometimes.

rhia
Nintex Newbie

In case anyone runs into the issue and ends up here like I did: if you have a repeating section in O365 and are trying to use Get Item From Collection to retrieve a date and put it in a date variable, you're going to need to use a text variable and then convert it. You can, surprisingly, drop that text variable right into a date/time column. SPO didn't yell at me about this, and I was shocked.

(I ended up here trying to figure out how to convert the txt string to a date variable.)

sphillips
Nintex Newbie

Thank you Andrew. This is a very comprehensive list applicable to most business cases I would guess, but how does one go about creating a date format like "28-NOV-2017"?

The global enterprise client I am working with currently would like to use this configuration.

andrewg
Nintex Newbie

Try

fn-FormatDate({CurrentDate}, "d-MMM-yyyy")

use 'dd' if you want the day to read 03 instead of 3 (using 'd') when it's the 3rd of the month.

csantos
Nintex Newbie

Could you help me concatenate this into a Single line of text field? I'm trying to use the Build String action with the date format to generate control numbers on a list, but the date format isn't returning properly. What am I doing wrong here?

Input (Build String action):

8D-fn-FormatDate(‎‏{Variable:startyear}‌,"yyyy")-‎‏{Variable:IDnumber}

Output field (Single line of text format):

8D-fn-FormatDate(1/1/0001 12:00:00 AM,"yyyy")-058

andrewg
Nintex Newbie

You probably want to do this in two steps because of the text surrounding the inline function may confuse the rules engine. Do fn-FormatDate({Variable:startyear},"yyyy") in a variable first, then add it to the field update 

8D-{Variable:actualyear}-{Variable:IDnumber}

bimi82
Nintex Newbie

Hello

is it possible to combine / concatenate the CurrentDate and CurrentTime together?

I have been trying the flowing variable in an Update Item :

fn-FormatDate(Current Date,"ddMMyy")fn-FormatDate(Current Time,"HH:mm:ss")

My intention is to be like 150118132310 (without any semicolons or dots.)

Current Date 150118

Current Time 132310 (HH MM SS)

Any advise?

mlauer
Nintex Newbie

Should work. I used following in Build String action and it's working:

fn-FormatDate({Common:CurrentDate},yyyyMMdd)_fn-FormatDate({Common:CurrentTime},HHmmss)

eyalseg
Nintex Newbie

How can one change the  CultureInfo.CurrentCulture format? I want to use "he-HE" format of date

emha
Nintex Newbie

it's browser's internal variable which is automatically being configured by your user profile and/or site settings

bo55vxr
Nintex Newbie

I am trying this but SECONDS is always showing "00" ... 

FormatDate({Common:CurrentDate},"yyyyMMdd")_FormatDate({Common:CurrentTime},"HHmmss")

Using RESPONSIVE form mode.

joseph_cervi
Nintex Newbie

I am getting the same issue on a form with a calculated value and in a workflow.   It's amazing the amount of effort you have to do for something as simple as the seconds in a data/time value.

Calculated Value - Formula

formatDate(SomeDate,"HH:mm:ss")

Workflow Action - Calculated Date

Results: "00" seconds where it should be "34"

bimi82
Nintex Newbie

Can you screenshot the Calculated Date function and the variable types you have used.
Make sure to use date/time variable to Store Date In: 

In my example it would be:

formatDate(dat_DateTimeSeconds,"HH:mm:ss")

hejones50
Nintex Newbie

Really helpful stuff! Thank you!

mastindianboy
Nintex Newbie

Hello, I am getting as it is string in string builder action, trying to get date in dd-MMM-yyyy format. Please see screenshot attached. 

woutert
Nintex Newbie

Today seems to be one of those days: It is/was January 2nd. But I got  a return from our fn-FormatDate("MMM dd") function of "Feb 01" . Source is a regular date field. Typical case of mixing up m/d/y and d/m/y formatting, it seems.

A date representation of January 2nd

Regional settings are on UTC time zone and English (United States) for this entire site collection. Had no problems since the 2nd half of December 2018 when this workflow started. As soon as numbers get above 12 there is no doubt of course.

Any easy suggestions to prevent this from happening?

andrewg
Nintex Newbie

Hm, I'm trying to remember when I've seen that before. I think I recall checking the server's region and time zone set up. Is this on-premise?

woutert
Nintex Newbie

I checked and you are correct it seems. Originally the on-premise installation of SP2016 was done in the UK and my site collection with this issue was on US region. Switching the entire site collection back to UK region solved the problem. Apparently this supersedes the site collection level.

andrewg
Nintex Newbie

Good to see that helped. It can be the reason, but not always. If the workflow is running under the owstimer service or workflow service on the server then it matters what the server is setup as. If the workflow runs in the AppPool it should take your context and not the servers. So if this was happening or not at some point and there was an "unexplained" changed, usually its that the workflows were paused naturally in the logic or there were too many running in the AppPool at one time and it was queued. Queued workflows run in the server's context when they start up. (And queued workflows can run within 5 minutes, not to mislead that its a long pause)

robyndennis
Nintex Newbie

This is an awesome resource and I will come back here often. Would you mind adding the "g" and "G" options as I think it would be really useful. It picks up the local date settings too so here in Australia the date shows correctly as 27/02/2019.

 

Thanks

 

"g"

General date/time pattern (short time)

fn-FormatDate({CurrentDate}, "g")

02/27/2019 3:27 PM

"G"

General date/time pattern (long time)

fn-FormatDate({CurrentDate}, "G")

02/27/2019 3:27:25 PM

 

Reference https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings