Date Formatting
1. :formatD(patternOut, patternIn)
Syntax Explanation
Formats a date by accepting an output format patternOut and an optional input format patternIn (defaults to ISO 8601).
Common Examples
More Format Examples
Result
The output is the date formatted as specified.
2. :addD(amount, unit, patternIn)
Syntax Explanation
Adds a specified amount of time to a date. Supported units include: day, week, month, quarter, year, hour, minute, second, millisecond.
Parameters:
- amount: The quantity to add.
- unit: The time unit (case-insensitive).
- patternIn: Optional, the input format (defaults to ISO8601).
Example
Result
The output is the new date after the specified time has been added.
3. :subD(amount, unit, patternIn)
Syntax Explanation
Subtracts a specified amount of time from a date. The parameters are the same as in addD.
Example
Result
The output is the new date after the specified time has been subtracted.
4. :startOfD(unit, patternIn)
Syntax Explanation
Sets the date to the start of the specified time unit.
Parameters:
- unit: The time unit.
- patternIn: Optional, the input format.
Example
Result
The output is the date set to the start of the specified unit.
5. :endOfD(unit, patternIn)
Syntax Explanation
Sets the date to the end of the specified time unit.
Parameters are the same as for startOfD.
Example
Result
The output is the date set to the end of the specified unit.
6. :diffD(toDate, unit, patternFromDate, patternToDate)
Syntax Explanation
Calculates the difference between two dates and outputs it in the specified unit. Supported units include:
day(s)ordweek(s)orwquarter(s)orQmonth(s)orMyear(s)oryhour(s)orhminute(s)ormsecond(s)orsmillisecond(s)orms(default unit)
Parameters:
- toDate: The target date.
- unit: The unit for output.
- patternFromDate: Optional, the format of the starting date.
- patternToDate: Optional, the format of the target date.
Example
Result
The output is the time difference between the two dates, converted into the specified unit.
7. :convDate(patternIn, patternOut)
Syntax Explanation
Converts a date from one format to another (not recommended for use).
Parameters:
- patternIn: The input date format.
- patternOut: The output date format.
Example
Result
The output is the date converted to the specified format.
8. Date Format Patterns
Common date format symbols (refer to the DayJS documentation):
X: Unix timestamp (in seconds), e.g., 1360013296x: Unix timestamp in milliseconds, e.g., 1360013296123YY: Two-digit year, e.g., 18YYYY: Four-digit year, e.g., 2018M,MM,MMM,MMMM: Month (number, two-digit, abbreviated, full name)D,DD: Day (number, two-digit)d,dd,ddd,dddd: Day of the week (number, minimal, abbreviated, full name)H,HH,h,hh: Hour (24-hour or 12-hour clock)m,mm: Minutes,ss: SecondSSS: Millisecond (3 digits)Z,ZZ: UTC offset, e.g., +05:00 or +0500A,a: AM/PMQ: Quarter (1-4)Do: Day of month with ordinal, e.g., 1st, 2nd, …- For other formats, refer to the full documentation.
Additionally, there are localized formats based on language such asLT,LTS,L,LL,LLL,LLLL, etc.

