informat.date Date Operations
Overview
Use the informat.date object to perform date-related operations
format
Format date
informat.date.format(date, format);| Parameter | Type | Description |
|---|---|---|
| date | Date | Date object |
| format | String | Format expression |
Return Value
Type String, formatted string
Example
informat.date.format(new Date(), "yyyy-MM-dd HH:mm:ss");2023-05-09 11:04:48parse
Parse date from string
informat.date.parse(str, format);| Parameter | Type | Description |
|---|---|---|
| str | String | Date string |
| format | String | Format expression |
Return Value
Type Date, returns null if parsing fails
Example
informat.date.parse("2023-05-09 11:04:48", "yyyy-MM-dd HH:mm:ss");Tue May 09 11:04:48 CST 2023parseDate
Parse date from string
informat.date.parseDate(str);| Parameter | Type | Description |
|---|---|---|
| str | String | Date string |
Return Value
Type Date, returns null if parsing fails
Example
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");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 2025dateToTimestamp
Convert date type to UNIX timestamp number value
informat.date.dateToTimestamp(date);| Parameter | Type | Description |
|---|---|---|
| date | Date | Date object |
Return Value
Type Integer UNIX timestamp number value, returns null if date is null
Example
informat.date.dateToTimestamp(new Date());1667232000000timestampToDate
Convert UNIX timestamp number value to date type
informat.date.timestampToDate(date);| Parameter | Type | Description |
|---|---|---|
| timestamp | Integer | UNIX timestamp number value |
Return Value
Type Date Converted date, returns null if timestamp is null
Example
informat.date.timestampToDate(1667232000000);Tue Nov 01 00:00:00 CST 2022getDateOfThisWeek
Get date of this week
informat.date.getDateOfThisWeek(dayOfWeek);| Parameter | Type | Description |
|---|---|---|
| dayOfWeek | int | Day of week, value is between 1 and 7 |
Return Value
Type Date
Example
informat.date.getDateOfThisWeek(7);Tue Apr 06 00:00:00 CST 2025getMonday
Get Monday of this week
informat.date.getMonday();Return Value
Type Date
Example
informat.date.getMonday();Mon Apr 21 00:00:00 CST 2025getMonday
Get Monday of this week
informat.date.getMonday(date);| Parameter | Type | Description |
|---|---|---|
| date | Date | Date object |
Return Value
Type Date
Example
informat.date.getMonday(new Date());Mon Apr 14 00:00:00 CST 2025getStartOfDay
Get 00:00:00 of this day
informat.date.getStartOfDay();Return Value
Type Date
Example
informat.date.getStartOfDay();Tue Apr 06 00:00:00 CST 2025getStartOfDay
Get 00:00:00 of this day
informat.date.getStartOfDay(date);| Parameter | Type | Description |
|---|---|---|
| date | Date | Date object |
Return Value
Type Date
Example
informat.date.getStartOfDay(new Date());Tue Apr 06 00:00:00 CST 2025getStartOfMonth
Get 1st day of this month, such as 5th 1st 00:00:00 (hour, minute, second, millisecond are all 0)
informat.date.getStartOfMonth();Return Value
Type Date
Example
informat.date.getStartOfMonth();Tue Apr 01 00:00:00 CST 2025getStartOfMonth
Get 1st day of this month, such as 5th 1st 00:00:00 (hour, minute, second, millisecond are all 0)
informat.date.getStartOfMonth(date);| Parameter | Type | Description |
|---|---|---|
| date | Date | Date object |
Return Value
Type Date
Example
informat.date.getStartOfMonth(new Date());Tue Apr 01 00:00:00 CST 2025getStartOfYear
Get 1st day of this year, such as 2025-01-01 00:00:00 (hour, minute, second, millisecond are all 0)
informat.date.getStartOfYear();Return Value
Type Date
Example
informat.date.getStartOfYear();Wed Jan 01 00:00:00 CST 2025getStartOfYear
Get 1st day of this year, such as 2025-01-01 00:00:00 (hour, minute, second, millisecond are all 0)
informat.date.getStartOfYear(date);| Parameter | Type | Description |
|---|---|---|
| date | Date | Date object |
Return Value
Type Date
Example
informat.date.getStartOfYear(new Date());Wed Jan 01 00:00:00 CST 2025isSameDay
Check if two dates are the same day
informat.date.isSameDay(date1, date2);| Parameter | Type | Description |
|---|---|---|
| date1 | Date | Date object 1 |
| date2 | Date | Date object 2 |
Return Value
Type Boolean
Example
informat.date.isSameDay(date1, date2);truedateAdd
Add or subtract days, months, years, etc. from a date
informat.date.dateAdd(d, type, value);| Parameter | Type | Description |
|---|---|---|
| d | Date or Long | Date or UNIX timestamp to calculate |
| type | String | Offset unit |
| diff | Integer | Value 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
//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,000dateBefore
Determine if date d1 is before date d2
informat.date.dateBefore(d1, d2);| Parameter | Type | Description |
|---|---|---|
| d1 | Date or Long | Date object 1 or UNIX timestamp |
| d2 | Date or Long | Date 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
//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); //falsedatePart
Return the specified part of date d based on type
informat.date.datePart(d, type);| Parameter | Type | Description |
|---|---|---|
| d | Date or Long | Date or UNIX timestamp to calculate |
| type | String | Operation 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
//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
