Skip to content

informat.date Date Operations

Overview

Use the informat.date object to perform date-related operations

format

Format date

javascript
informat.date.format(date, format);
ParameterTypeDescription
dateDateDate object
formatStringFormat expression

Return Value

Type String, formatted string

Example

javascript
informat.date.format(new Date(), "yyyy-MM-dd HH:mm:ss");
text
2023-05-09 11:04:48

parse

Parse date from string

javascript
informat.date.parse(str, format);
ParameterTypeDescription
strStringDate string
formatStringFormat expression

Return Value

Type Date, returns null if parsing fails

Example

javascript
informat.date.parse("2023-05-09 11:04:48", "yyyy-MM-dd HH:mm:ss");
text
Tue May 09 11:04:48 CST 2023

parseDate

Parse date from string

javascript
informat.date.parseDate(str);
ParameterTypeDescription
strStringDate string

Return Value

Type Date, returns null if parsing fails

Example

javascript
informat.date.parseDate("2023-05-09 11:04:48");
informat.date.parseDate("2023-05-09 11:04");
informat.date.parseDate("2023-05-09 11");
informat.date.parseDate("2023-05-09");
informat.date.parseDate("2018-10-26T07:01:26Z");
informat.date.parseDate("1741337150957");
text
Tue May 09 11:04:48 CST 2023
Tue May 09 11:04:00 CST 2023
Tue May 09 00:00:00 CST 2023
Tue May 09 00:00:00 CST 2023
Fri Oct 26 15:01:26 CST 2018
Fri Mar 07 16:45:50 CST 2025

dateToTimestamp

Convert date type to UNIX timestamp number value

javascript
informat.date.dateToTimestamp(date);
ParameterTypeDescription
dateDateDate object

Return Value

Type Integer UNIX timestamp number value, returns null if date is null

Example

javascript
informat.date.dateToTimestamp(new Date());
text
1667232000000

timestampToDate

Convert UNIX timestamp number value to date type

javascript
informat.date.timestampToDate(date);
ParameterTypeDescription
timestampIntegerUNIX timestamp number value

Return Value

Type Date Converted date, returns null if timestamp is null

Example

javascript
informat.date.timestampToDate(1667232000000);
text
Tue Nov 01 00:00:00 CST 2022

getDateOfThisWeek

Get date of this week

javascript
informat.date.getDateOfThisWeek(dayOfWeek);
ParameterTypeDescription
dayOfWeekintDay of week, value is between 1 and 7

Return Value

Type Date

Example

javascript
informat.date.getDateOfThisWeek(7);
text
Tue Apr 06 00:00:00 CST 2025

getMonday

Get Monday of this week

javascript
informat.date.getMonday();

Return Value

Type Date

Example

javascript
informat.date.getMonday();
text
Mon Apr 21 00:00:00 CST 2025

getMonday

Get Monday of this week

javascript
informat.date.getMonday(date);
ParameterTypeDescription
dateDateDate object

Return Value

Type Date

Example

javascript
informat.date.getMonday(new Date());
text
Mon Apr 14 00:00:00 CST 2025

getStartOfDay

Get 00:00:00 of this day

javascript
informat.date.getStartOfDay();

Return Value

Type Date

Example

javascript
informat.date.getStartOfDay();
text
Tue Apr 06 00:00:00 CST 2025

getStartOfDay

Get 00:00:00 of this day

javascript
informat.date.getStartOfDay(date);
ParameterTypeDescription
dateDateDate object

Return Value

Type Date

Example

javascript
informat.date.getStartOfDay(new Date());
text
Tue Apr 06 00:00:00 CST 2025

getStartOfMonth

Get 1st day of this month, such as 5th 1st 00:00:00 (hour, minute, second, millisecond are all 0)

javascript
informat.date.getStartOfMonth();

Return Value

Type Date

Example

javascript
informat.date.getStartOfMonth();
text
Tue Apr 01 00:00:00 CST 2025

getStartOfMonth

Get 1st day of this month, such as 5th 1st 00:00:00 (hour, minute, second, millisecond are all 0)

javascript
informat.date.getStartOfMonth(date);
ParameterTypeDescription
dateDateDate object

Return Value

Type Date

Example

javascript
informat.date.getStartOfMonth(new Date());
text
Tue Apr 01 00:00:00 CST 2025

getStartOfYear

Get 1st day of this year, such as 2025-01-01 00:00:00 (hour, minute, second, millisecond are all 0)

javascript
informat.date.getStartOfYear();

Return Value

Type Date

Example

javascript
informat.date.getStartOfYear();
text
Wed Jan 01 00:00:00 CST 2025

getStartOfYear

Get 1st day of this year, such as 2025-01-01 00:00:00 (hour, minute, second, millisecond are all 0)

javascript
informat.date.getStartOfYear(date);
ParameterTypeDescription
dateDateDate object

Return Value

Type Date

Example

javascript
informat.date.getStartOfYear(new Date());
text
Wed Jan 01 00:00:00 CST 2025

isSameDay

Check if two dates are the same day

javascript
informat.date.isSameDay(date1, date2);
ParameterTypeDescription
date1DateDate object 1
date2DateDate object 2

Return Value

Type Boolean

Example

javascript
informat.date.isSameDay(date1, date2);
text
true

dateAdd

Add or subtract days, months, years, etc. from a date

javascript
informat.date.dateAdd(d, type, value);
ParameterTypeDescription
dDate or LongDate or UNIX timestamp to calculate
typeStringOffset unit
diffIntegerValue to add or subtract, defaults to 0 if null. Use positive for add, negative for subtract

INFO

type values: year:year,month:month,day_of_year:day_of_year,day_of_month:day_of_month,day_of_week:day_of_week,hour:hour,minute:minute,second:second,millisecond:millisecond

Return Value

Type Date

Example

javascript
//Assume date value is 2022-11-01 00:00:00,000, timestamp is 1667232000000
informat.date.dateAdd(date, "year", 1); //2023-11-01 00:00:00,000
informat.date.dateAdd(date, "year", null); //2022-11-01 00:00:00,000
informat.date.dateAdd(date, "year", -1); //2021-11-01 00:00:00,000
informat.date.dateAdd(date, "month", 1); //2022-12-01 00:00:00,000
informat.date.dateAdd(date, "day_of_year", 1); //2022-11-02 00:00:00,000
informat.date.dateAdd(date, "day_of_month", 1); //2022-11-02 00:00:00,000
informat.date.dateAdd(date, "day_of_week", 1); //2022-11-02 00:00:00,000
informat.date.dateAdd(date, "hour", 1); //2022-11-01 01:00:00,000
informat.date.dateAdd(date, "minute", 1); //2022-11-01 00:01:00,000
informat.date.dateAdd(date, "second", 1); //2022-11-01 00:00:01,000
informat.date.dateAdd(date, "millisecond", 1); //2022-11-01 00:00:00,001
informat.date.dateAdd(timestamp, "year", 2); //2024-11-01 00:00:00,000
informat.date.dateAdd(timestamp, "month", 1); //2022-12-01 00:00:00,000

dateBefore

Determine if date d1 is before date d2

javascript
informat.date.dateBefore(d1, d2);
ParameterTypeDescription
d1Date or LongDate object 1 or UNIX timestamp
d2Date or LongDate object 2 or UNIX timestamp

Return Value

Type Boolean Returns true if date d1 is before date d2, false if d1 and d2 are equal

Example

javascript
//Assume date1 value is 2022-11-01 13:10:12,000, timestamp1 is 1667279412000
//Assume date2 value is 2022-02-02 13:10:12,000, timestamp2 is 1643778612000

informat.date.dateBefore(date1, date2); //false
informat.date.dateBefore(date2, date1); //true
informat.date.dateBefore(timestamp1, timestamp2); //false
informat.date.dateBefore(timestamp2, timestamp1); //true
informat.date.dateBefore(timestamp1, date2); //false
informat.date.dateBefore(timestamp2, date1); //true
informat.date.dateBefore(date1, null); //false
informat.date.dateBefore(null, date2); //false
informat.date.dateBefore(timestamp1, null); //false
informat.date.dateBefore(null, timestamp2); //false
informat.date.dateBefore(null, null); //false

datePart

Return the specified part of date d based on type

javascript
informat.date.datePart(d, type);
ParameterTypeDescription
dDate or LongDate or UNIX timestamp to calculate
typeStringOperation type

INFO

  • type values: year:year,month:month,day_of_year:day_of_year,day_of_month:day_of_month,day_of_week:day_of_week,hour:hour,minute:minute,second:second,millisecond:millisecond
  • month is 0-based, for example, if date is November, informat.date.datePart(date, 'month'); returns 10

Return Value

Type Integer The specified part of date d based on type

Example

javascript
//Assume date value is 2022-11-01 13:10:12,000, timestamp is 1667279412000
informat.date.datePart(date, "year"); //2022
informat.date.datePart(date, "month"); //10
informat.date.datePart(date, "day_of_year"); //305
informat.date.datePart(date, "day_of_month"); //1
informat.date.datePart(date, "day_of_week"); //3
informat.date.datePart(date, "hour"); //13
informat.date.datePart(date, "minute"); //10
informat.date.datePart(date, "second"); //12
informat.date.datePart(date, "millisecond"); //0
informat.date.datePart(null, "year"); //null
informat.date.datePart(date, null); //null
informat.date.datePart(timestamp, "year"); //2022
informat.date.datePart(timestamp, "month"); //10
informat.date.datePart(date, "week_of_year"); //45