toDate: Convert a string to a Date

NimbleText enhances javascript's Date handling capabilities by adding a way to format dates (the format function, see Date Format) and also a way to parse strings into dates: the toDate function.

For example, given the string:

01 Jan 2020

You can turn it into a Date object, like so:

<% $0.toDate('dd n yyyy') %>

The difficult bit is crafting the mask that identifies the date format you are parsing.

Here are some examples

Examples

Input Pattern Result
01 Jan 2020 <% '$0'.toDate('dd n yyyy') %> Wed Jan 01 2020 00:00:00
12/06/31 <% '$0'.toDate("dd/MM/yy") %> Fri Jun 12 1931 00:00:00
17 Feb 2021 <% '$0'.toDate("dd n y") %> Wed Feb 17 2021 00:00:00
17 February 2021 <% '$0'.toDate("dd N y") %> Wed Feb 17 2021 00:00:00
2023-06-21 23:12 <% '$0'.toDate("yyyy-MM-dd HH:mm") %> Wed Jun 21 2023 23:12:00
01 Feb 2021 11am <% '$0'.toDate("dd nnn yyyy haa") %> Mon Feb 01 2021 11:00:00
01 Feb 2021 11pm <% '$0'.toDate("dd nnn yyyy haa") %> Mon Feb 01 2021 23:00:00
01 Feb 2021 11:23:21.555 <% '$0'.toDate("dd nnn yyyy HH:mm:s.S").getMilliseconds() %> 555

Characters

Character Meaning Examples
Y Full year 2021
y 2 digit year 21
M Month number 01
n Month short name Jan
N Month (full name) January
d Date ??
m minutes 57
H Hours (24 hour time) 21
h hours (12 hour time) 9
s Seconds 52
S Milliseconds 123
a Meridian (AM or PM) AM, PM
w Weekday (short names) Mon, Tue
W Weekday (full names) Monday, Tuesday
z Timezone offset ...

Further help

You can also get general help, help on all the symbols and keywords, or on the built-in functions, filtering with a where clause, help with the powerful command-line automation, or applying custom formats to your dates and times.

You need to purchase a license to unlock all the features in NimbleText.

If you haven't downloaded NimbleText yet, then for added power, privacy and versatility I sincerely think you should download it now.

Download NimbleText