Skip to content
Latchkey

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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →