Returns the given date as a string, formatted according to a pattern. The pattern is a format that is full of various placeholders that will display different parts of the date. These are case-sensitive! These placeholders can be repeated for a different effect. For example, M will give you 1-12, MM will give you 01-12, MMM will give you Jan-Dec, MMMM will give you January-December.

 The placeholders are:

SymbolDescriptionPresentationExamplesOther Notes
GEra designatorTextG=AD 
yYearYearyyyy=1996; yy=96Lowercase y is the most commonly used year symbol
YWeek yearYearYYYY=2009; YY=09Capital Y gives the year based on weeks (ie. changes to the new year up to a week early)
MMonth in yearMonthMMMM=July; MMM=Jul; MM=07 
wWeek in yearNumber27If Dec31 is mid-week, it will be in week 1 of the next year
WWeek in monthNumber2 
DDay in yearNumber189 
dDay in monthNumber10 
FDay of week in monthNumber22nd Sunday of the month
EDay name in weekTextEEEE=Tuesday; E=Tue 
uDay number of weekNumber1(1 = Monday, ..., 7 = Sunday)
aAm/Pm markerTextPM 
HHour in day (0-23)Number0 
hHour in am/pm (1-12)Number12  
kHour in day (1-24)Number24 
KHour in am/pm (0-11)Number0 
mMinute in hourNumber30 
sSecond in minuteNumber55 
SMillisecondNumber978 
zTime zoneGeneral time zonezzzz=Pacific Standard Time; z=PST 
ZTime zoneRFC 822 time zoneZ=-0800 
XTime zoneISO 8601 time zoneX=-08; XX=-0800; XXX=-08:00 

  

Expert Tip: This function uses the Java class java.text.SimpleDateFormat internally, and will accept any valid format string for that class.



dateFormat(date, pattern)

  • Parameter

Date date - The starting date.

string pattern - The pattern to format the given date to.

  • Results

string - The given date formatted based on the given format pattern.



dateFormat(toDate("2003-9-14 8:00:00"), "yyyy-MM-dd HH:mm:ss") //returns the string "2003-09-14 08:00:00" This format is accepted in most databases


dateFormat(toDate("2003-9-14 8:00:00"), "yyyy-MM-dd h a") //returns the string "2003-09-14 8 AM"


dateFormat(toDate("2003-9-14 8:00:00"), "MMM d, yyyy") //returns the string "Sep 14, 2003"


dateFormat(now(), 'yyyy-MM-dd 00:00:00') //returns the current date, but forces the time to 00:00:00