date Command Reference for CI Scripts
date prints or formats the current time, and can compute relative dates.
date stamps artifacts, builds version tags, and measures durations. Use UTC for reproducibility, and beware that date arithmetic differs sharply between GNU and BSD date.
Common flags/usage
- +FORMAT: choose the output format (e.g. +%Y-%m-%d)
- -u: use UTC instead of local time
- %s: Unix epoch seconds
- -d "STR" (GNU): parse or compute a date
- -Iseconds: ISO 8601 output
Example
shell
TAG="build-$(date -u +%Y%m%d-%H%M%S)"
echo "tag=${TAG}" >> "${GITHUB_OUTPUT}"
START=$(date +%s) ; ./build.sh ; echo "took $(( $(date +%s) - START ))s"In CI
Always use date -u for timestamps in tags and filenames so the value does not depend on the runner timezone. Date arithmetic is not portable: GNU uses date -d "+1 day" while BSD/macOS uses date -v+1d. For durations, subtract two date +%s epoch readings, which works everywhere.
Key takeaways
- Use date -u so timestamps do not depend on the runner timezone.
- date +%s epoch seconds give portable duration math via subtraction.
- date -d (GNU) and date -v (BSD) arithmetic are incompatible.
Related guides
printf Command Reference for CI Scriptsprintf formats output predictably in CI, unlike echo. Reference for format specifiers, %s, %b, and escapes, p…
timeout Command Reference for CI Scriptstimeout caps how long a command may run in CI, preventing hangs. Reference for duration units, -k kill-after,…
mktemp Command Reference for CI Scriptsmktemp creates unique temp files and directories safely in CI. Reference for -d, templates, and -t, plus the…
sha256sum Command Reference for CI Scriptssha256sum computes and verifies checksums in CI for download integrity. Reference for -c verify mode, --statu…