Date Tools
Date Functions
Usage
dateAdd [ --days delta ] [ timestamp ... ]
Add or subtract days from a text date
Writes to standard output
Date with days added to it
Arguments
--days delta- SignedInteger. Number of days to add (or subtract - use a negative number). Affects all timestamps after it.timestamp ...- Date. Timestamp to update.
Examples
newYearsEve=$(dateAdd --days -1 "2025-01-01")
Return codes
0- Success1- Environment error2- Argument error
Usage
dateValid [ --help ] [ -- ] text
Is a date valid?
Arguments
--help- Flag. Optional. Display this help.--- Flag. Optional. Stops command processing to enable arbitrary text to be passed as additional arguments without special meaning.text- String. Required. Text to validate as a date after the year 1600. Does not validate month and day combinations.
Return codes
0- Success1- Environment error2- Argument error
Usage
dateToFormat date [ format ]
Converts a date (YYYY-MM-DD) to another format.
Compatible with BSD and GNU date.
Arguments
date- String. Required. String in the formYYYY-MM-DD(e.g.2023-10-15)format- String. Optional. Format string for thedatecommand (e.g.%s)
Examples
dateToFormat 2023-04-20 %s 1681948800
timestamp=$(dateToFormat '2023-10-15' %s)
Return codes
1- if parsing fails0- if parsing succeeds
Usage
dateToTimestamp [ date ] [ --help ]
Converts a date to an integer timestamp
Arguments
date- String in the formYYYY-MM-DD(e.g.2023-10-15)--help- Flag. Optional. Display this help.
Examples
timestamp=$(dateToTimestamp '2023-10-15')
Return codes
1- if parsing fails0- if parsing succeeds
Environment
- Compatible with BSD and GNU date.
Usage
dateFromTimestamp integerTimestamp [ format ] [ --help ] [ --local ]
Converts an integer date to a date formatted timestamp (e.g. %Y-%m-%d %H:%M:%S) dateFromTimestamp 1681966800 %F
Arguments
integerTimestamp- Integer. Required. Integer timestamp offset (unix timestamp, same as$(date +%s))format- String. Optional. How to output the date (e.g.%F- no+is required)--help- Flag. Optional. Display this help.--local- Flag. Optional. Show the local time, not UTC.
Examples
dateField=$(dateFromTimestamp $init %Y)
Return codes
0- If parsing is successful1- If parsing fails
Environment
- Compatible with BSD and GNU date.
Now Relative
Usage
dateToday [ --local ] [ --help ]
Returns the current date, in YYYY-MM-DD format. (same as %F)
Arguments
--local- Flag. Optional. Local today.--help- Flag. Optional. Display this help.
Examples
date="$(dateToday)"
Return codes
0- Success1- Environment error2- Argument error
Environment
- Compatible with BSD and GNU date.
Usage
dateYesterday [ --local ] [ --help ]
Returns yesterday's date, in YYYY-MM-DD format. (same as %F)
Arguments
--local- Flag. Optional. Local yesterday--help- Flag. Optional. Display this help.
Examples
rotated="$log.$(dateYesterday --local)"
Return codes
0- Success1- Environment error2- Argument error
Usage
dateTomorrow [ --local ] [ --help ]
Returns tomorrow's date (UTC time), in YYYY-MM-DD format. (same as %F)
Arguments
--local- Flag. Optional. Local tomorrow--help- Flag. Optional. Display this help.
Examples
rotated="$log.$(dateTomorrow)"
Return codes
0- Success1- Environment error2- Argument error