Date Tools
Date Functions
dateAdd
Add or subtract days from a text date
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
dateValid
Is a date valid?
Usage
dateValid [ --help ] [ -- ] text
Is a date valid?
Arguments
--help- Optional. Flag. Display this help.--- Optional. Flag. 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
dateToFormat
Platform agnostic date conversion
Usage
dateToFormat date format
Converts a date (YYYY-MM-DD) to another format.
Return Code: 1 - if parsing fails
Return Code: 0 - if parsing succeeds
Arguments
date- String in the formYYYY-MM-DD(e.g.2023-10-15)format- Format string for thedatecommand (e.g.%s)
Examples
dateToFormat 2023-04-20 %s 1681948800
timestamp=$(dateToFormat '2023-10-15' %s)
Return codes
0- Success1- Environment error2- Argument error
Environment
- Compatible with BSD and GNU date.
dateToTimestamp
Converts a date to an integer timestamp
Usage
dateToTimestamp date
Converts a date to an integer timestamp
Return Code: 1 - if parsing fails Return Code: 0 - if parsing succeeds
Arguments
date- String in the formYYYY-MM-DD(e.g.2023-10-15)--help- Optional. Flag. Display this help.
Examples
timestamp=$(dateToTimestamp '2023-10-15')
Return codes
0- Success1- Environment error2- Argument error
Environment
- Compatible with BSD and GNU date.
dateFromTimestamp
Converts an integer date to a date formatted timestamp (e.g.
Usage
dateFromTimestamp integerTimestamp format
Converts an integer date to a date formatted timestamp (e.g. %Y-%m-%d %H:%M:%S)
dateFromTimestamp 1681966800 %F
Return Code: 0 - If parsing is successful Return Code: 1 - If parsing fails
Arguments
integerTimestamp- Integer timestamp offset (unix timestamp, same as$(date +%s))format- How to output the date (e.g.%F- no+is required)--help- Optional. Flag. Display this help.
Examples
dateField=$(dateFromTimestamp $init %Y)
Return codes
0- Success1- Environment error2- Argument error
Environment
- Compatible with BSD and GNU date.
Now Relative
todayDate
Today's date in UTC
Usage
todayDate [ --local ] [ --help ]
Returns the current date, in YYYY-MM-DD format. (same as %F)
Arguments
--local- Flag. Optional. Local today.--help- Optional. Flag. Display this help.
Examples
date="$(todayDate)"
Return codes
0- Success1- Environment error2- Argument error
Environment
- Compatible with BSD and GNU date.
yesterdayDate
Yesterday's date (UTC time)
Usage
yesterdayDate [ --local ] [ --help ]
Returns yesterday's date, in YYYY-MM-DD format. (same as %F)
Arguments
--local- Flag. Optional. Local yesterday--help- Optional. Flag. Display this help.
Examples
rotated="$log.$(yesterdayDate --local)"
Return codes
0- Success1- Environment error2- Argument error
tomorrowDate
Tomorrow's date in UTC
Usage
tomorrowDate [ --local ] [ --help ]
Returns tomorrow's date (UTC time), in YYYY-MM-DD format. (same as %F)
Arguments
--local- Flag. Optional. Local tomorrow--help- Optional. Flag. Display this help.
Examples
rotated="$log.$(tomorrowDate)"
Return codes
0- Success1- Environment error2- Argument error