format-date-column

Define the format of a date-time column

Define the format of a date-time column and either replace the original column values or add a new column with the reformatted date-time.

Arguments

Inputs:

data: The datatable containing a column of date values.

source column: The name of the column containing date-time values you want to reformat.

source format: The format of the date-time values in the source column, based on Unicode Technical Standard #35. See https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table. Defaults to ISO 8601.

target column: The name of the column that will contain the formatted date-time values. If unspecified, it defaults to the 'source column' and will replace the original values.

target format: The desired format of the date-time values in the target column, based on Unicode Technical Standard #35. See https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table. Defaults to yy-MM-dd. TIP: for Microreact projects, ISO 8601 is ideal (yyyy-MM-dd). Using this format Microreact will interpret it correctly and display in browsers using the local browser preferences.

locale: A language locale to be used when formatting the values. See https://date-fns.org/v2.0.1/docs/I18n#supported-languages or https://github.com/date-fns/date-fns/tree/38ff3a18ad84d990b6ebcff1c120ea7ee4400b69/src/locale for a list of supported languages and locale options. If unspecified, locale defaults to 'en-GB'.

Output:

data: A datatable containing formatted date values in the target column.

Date Formats

The table below shows some common formats. More information and other format symbols can be found on the Unicode site.

ExampleFormat symbols

2009-06-15T13:45:30.345

yyyy-MM-dd'T'HH:mm:ss.SSS

6/15/09

M/d/yy OR M/dd/yy

06/15/2009

MM/dd/yyyy

15-6-09

dd-M-yy

1:45 PM

hh:mm a

13:45

HH:mm

15 Jun 2009

dd LLL yyyy

Example

Output from Example data-flo (last column is reformatted)

Possible use cases

  • Standardize date-time formats across different columns with different formats.

  • Simplify date-time into simple date.

  • Reformat date to align with a new target audience.

Last updated