Date Tools
dateAdd
Add or subtract days from a text date
Usage
dateAdd [ --days delta ] [ timestamp ... ]
Add or subtract days from a text date
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.
Writes to standard output
Date with days added to it
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
Checks a date syntax and ensures it's a valid calendar date.
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
dateToFormat
Platform agnostic date conversion
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
dateToTimestamp
Converts a date to an integer timestamp
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.
dateFromTimestamp
Converts an integer date to a date formatted timestamp (e.g.
Usage
dateFromTimestamp integerTimestamp [ format ] [ --help ] [ --local ]
Converts an integer date to a date formatted timestamp (e.g. %Y-%m-%d %H:%M:%S)
Arguments
integerTimestamp- Integer. Required. Integer. Required. Integer timestamp offset (Seconds since 1/1/1970 UTC, 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
dateFromTimestamp 1681966800 %F
dateField=$(dateFromTimestamp $init %Y)
Return codes
0- If parsing is successful1- If parsing fails
Environment
- Compatible with BSD and GNU date.
dateWithinDays
Is a date in the past beyond its expiration date?
Usage
dateWithinDays keyDate [ upToDateDays ] [ --name name ] [ --help ]
stdout: Two tokens on a single line:
This tool checks the keyDate and checks if it is within days of today; if not this fails.
It will also fail if:
- keyDate is empty or has an invalid value
- upToDateDays is less than zero
Arguments
keyDate- Date. Required. Formatted likeYYYY-MM-DD. Truncated at 10 characters as well.upToDateDays- Integer. Optional. Days that key expires afterkeyDate. Default is 90.--name name- String. Optional. Name of the expiring item for error messages.--help- Flag. Optional. Display this help.
Writes to standard output
- UnsignedInteger. Days until expiration.
- UnsignedInteger. Expiration timestamp.
Examples
if ! dateWithinDays "$AWS_ACCESS_KEY_DATE" 90; then
decorate big Failed, update key and reset date
exit 99
fi
Return codes
0- The date has not expired.1- The date has expired.2- The date is incorrectly formatted.2- Argument error.
Now Relative
dateToday
Today's date in UTC
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.
dateYesterday
Yesterday's date (UTC time)
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
dateTomorrow
Tomorrow's date in UTC
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