Date Formatting

Date and time text formatting for Real Time Clock (RTC) and FILE - "DATE" command.

The formatting characters used to determine how a date is represented in a text variable or text entity are detailed below.

It is possible to configure the textual strings representing the months of the year and days of the week to support different spoken languages. These are: short day text (ie "Mon", "Tue", ...), long day text (ie "Monday", "Tuesday", ...), suffix text (ie "st" for 1st, "nd" for 2nd, ...), short month text (ie "Jan", "Feb", ...), and long month text (ie "January", "February", ...).

Some simple Date Formatting Examples are given using the FILE() command and reading the time of day from the RTC.

Formatting Characters
Time and date formatting is determined by passing a string of characters to the appropriate command. Each character, shown in the table below, represents a particular element of the time and date (such as hours or years) and how it is to be formatted (such as a number or text representation). Characters that do not appear in the table are simply returned in the string unmodified. This allows separating characters, such as ":", "/" and spaces, to be inserted into the string, e.g using the formatting string "d/m/Y H:i" would return a date formatted as "09/08/2012 21:45".

Format
Character
DescriptionDefault Returned ValuesChangeable
Day
dDay of month with leading zeros01-31
jDay of month without leading zeros1-31
SOrdinal suffix for day of monthst, nd, rd, thYes, see Changing Suffix Text
DShort textual representation of dayMon, Tue, Wed, Thu,
Fri, Sat, Sun
Yes, see Changing Short Day Text
LFull textual representation of the day of the weekMonday, Tuesday, Wednesday,
Thursday, Friday, Saturday, Sunday
Yes, see Changing Long Day Text
NISO-8601 numeric representation of the day of the week1 (for Monday) - 7 (for Sunday)
Month
FFull textual representation of monthJanuary, February, March,
April, May, June,
July, August, September,
October, November, December
Yes, see Changing Long Month Text
mNumeric representation of month with leading zeros01-12
MShort textual representation of month, three lettersJan, Feb, Mar, Apr,
May, Jun, Jul, Aug,
Sep, Oct, Nov, Dec
Yes, see Changing Short Month Text
nNumeric representation of month without leading zeros1-12
Year
YFull numeric representation of year, 4 digits1900-2099
yTwo digit representation of year00-99
Time
aLowercase Ante meridiem and Post meridiemam, pm
AUppercase Ante meridiem and Post meridiemAM, PM
g12-hour format of hour without leading zeros1-12
G24-hour format of hour without leading zeros0-23
h12-hour format of hour with leading zeros01-12
H24-hour format of hour with leading zeros00-23
iMinutes with leading zeros00-59
sSeconds with leading zeros00-59


Back to Top



Changing Short Day Text
The strings for the short textual representation of the day of the week are preconfigured in text variable entities but can be changed by the user (eg to support different languages). The following table summarises the suffixes.

Default Text StringEntity NameMax LengthDescription
"Mon"DATE_MON_S4Short name for Monday (1st day of week)
"Tue"DATE_TUE_S4Short name for Tuesday (2nd day of week)
"Wed"DATE_WED_S4Short name for Wednesday (3rd day of week)
"Thu"DATE_THU_S4Short name for Thursday (4th day of week)
"Fri"DATE_FRI_S4Short name for Friday (5th day of week)
"Sat"DATE_SAT_S4Short name for Saturday (6th day of week)
"Sun"DATE_SUN_S4Short name for Sunday (7th day of week)

These strings are variables of type TXT4 and have a maximum length of 4 characters. They can be accessed and changed, as any other text variable. For example:

  LOAD( DATE_MON_S, "Lun" ); // Change default "Mon" to "Lun" for French.

Back to Top



Changing Long Day Text
The strings for the long textual representation of the day of the week are preconfigured in text variable entities but can be changed by the user (eg to support different languages). The following table summarises the suffixes.

Default Text StringEntity NameMax LengthDescription
"Monday"DATE_MON_L16Long name for Monday (1st day of week)
"Tuesday"DATE_TUE_L16Long name for Tuesday (2nd day of week)
"Wednesday"DATE_WED_L16Long name for Wednesday (3rd day of week)
"Thursday"DATE_THU_L16Long name for Thursday (4th day of week)
"Friday"DATE_FRI_L16Long name for Friday (5th day of week)
"Saturday"DATE_SAT_L16Long name for Saturday (6th day of week)
"Sunday"DATE_SUN_L16Long name for Sunday (7th day of week)

These strings are variables of type TXT16 and have a maximum length of 16 characters. They can be accessed and changed, as any other text variable. For example:

  LOAD( DATE_MON_L, "mercoled\\EC" ); // Change default "Wednesday" to "mercoledì" for Italian.

Back to Top



Changing Suffix Text
The strings for the ordinal suffixes for the day of month are preconfigured in text variable entities but can be changed by the user (eg to support different languages). The following table summarises the suffixes.

Default Text StringEntity NameMax LengthDescription
"st"DATE_DM_ST4Suffix for the 1st, 21st, and 31st days of the month
"nd"DATE_DM_ND4Suffix for the 2nd, and 22nd days of the month
"rd"DATE_DM_RD4Suffix for the 3rd, and 23rd days of the month
"th"DATE_DM_TH4Suffix for the 4th, 5th, 6th, 7th, 8th, 9th, 10th, 11th, 12th, 13th, 14th, 15th, 16th, 17th, 18th, 19th, 20th, 24th, 25th, 26th, 27th, 28th, 29th, and 30th days of the month

These strings are variables of type TXT4 and have a maximum length of 4 characters. They can be accessed and changed, as any other text variable. For example:

  LOAD( DATE_DM_RD, "RD" ); // Change default "rd" to uppercase "RD".

Back to Top



Changing Short Month Text
The strings for the short textual representation of the month of the year are preconfigured in text variable entities but can be changed by the user (eg to support different languages). The following table summarises the suffixes.

Default Text StringEntity NameMax LengthDescription
"Jan"DATE_JAN_S4Short name for January (1st month)
"Feb"DATE_FEB_S4Short name for February (2nd month)
"Mar"DATE_MAR_S4Short name for March (3rd month)
"Apr"DATE_APR_S4Short name for April (4th month)
"May"DATE_MAY_S4Short name for May (5th month)
"Jun"DATE_JUN_S4Short name for June (6th month)
"Jul"DATE_JUL_S4Short name for July (7th month)
"Aug"DATE_AUG_S4Short name for August (8th month)
"Sep"DATE_SEP_S4Short name for September (9th month)
"Oct"DATE_OCT_S4Short name for October (10th month)
"Nov"DATE_NOV_S4Short name for November (11th month)
"Dec"DATE_DEC_S4Short name for December (12th month)

These strings are variables of type TXT4 and have a maximum length of 4 characters. They can be accessed and changed, as any other text variable. For example:

  LOAD( DATE_DEC_S, "Dez" ); // Change default "Dec" to "Dez" for German.

Back to Top



Changing Long Month Text
The strings for the long textual representation of the month of the year are preconfigured in text variable entities but can be changed by the user (eg to support different languages). The following table summarises the suffixes.

Default Text StringEntity NameMax LengthDescription
"January"DATE_JAN_L16Long name for January (1st month)
"February"DATE_FEB_L16Long name for February (2nd month)
"March"DATE_MAR_L16Long name for March (3rd month)
"April"DATE_APR_L16Long name for April (4th month)
"May"DATE_MAY_L16Long name for May (5th month)
"June"DATE_JUN_L16Long name for June (6th month)
"July"DATE_JUL_L16Long name for July (7th month)
"August"DATE_AUG_L16Long name for August (8th month)
"September"DATE_SEP_L16Long name for September (9th month)
"October"DATE_OCT_L16Long name for October (10th month)
"November"DATE_NOV_L16Long name for November (11th month)
"December"DATE_DEC_L16Long name for December (12th month)

These strings are variables of type TXT16 and have a maximum length of 16 characters. They can be accessed and changed, as any other text variable. For example:

  LOAD( DATE_FEB_L, "febrero" ); // Change default "February" to "febrero" for Spanish.

Back to Top



Date Formatting Examples

Example 1 - FILE - "DATE"

  VAR( varTxt, "", TXT );
  FILE( "DATE", , varTxt, "d/m/Y H:i:s", "SDHC/images/pic1.bmp" );
  LOAD( RS2, "File Date:", varTxt ); // For example will send "File Date: 09/08/2012 21:19:32"

Example 2 - RTC with VAR style formatting

  STYLE( stRtcTxt, data ) { type=text; maxLen=48; format="L F jS, Y g:i:s A"; }
  VAR( varTxt, "", stRtcTxt );
  LOAD( varTxt, RTC );
  LOAD( RS2, "Time is:", varTxt ); // For example will send "Time is: Thursday August 8th, 2012 9:19:32 PM"

Example 3 - RTC with inline formatting

  VAR( varTxt, "", TXT );
  LOAD( varTxt, %d-M-Y%RTC ); // Use special case formatting for RTC
  LOAD( RS2, "Day is:", varTxt ); // For example will send "Day is: 08-Aug-2012"

Back to Top