datex
Print the date and time.
Mirrors GNU date. Run it as datex, or as gnux datex.
Synopsis
datex [OPTION]... [+FORMAT]GNU reference
Description
datex prints the current date and time, or the one -d STRING describes, in the C locale's default format ('Mon Jan 2 15:04:05 UTC 2006') or in +FORMAT. FORMAT takes GNU's conversions: %Y %m %d %H %M %S and friends, %a %A %b %B %p (in English), %s (seconds since the epoch), %N (nanoseconds), %z %:z %::z %:::z and %Z (zones), %j %U %W %V %G %u %w (day and week numbers), %F %T %D %R %r %c %x %X %h %e %k %l %C %y %g %n %t %%, and the flags -, _, 0, ^ and # with a field width (%-d, %_H, %10s). -I[FMT] prints ISO 8601 (date, hours, minutes, seconds or ns; date by default), --rfc-3339=FMT RFC 3339 (date, seconds or ns) and -R RFC 5322; only one output format may be given. -u uses UTC, and otherwise the TZ environment variable or the local zone applies. -d STRING accepts the forms GNU date accepts most often: 'now', 'today', 'yesterday', 'tomorrow', '@SECONDS', ISO 8601 and RFC 3339 dates and times, MM/DD/YYYY, 'Jan 2 2006', '2 Jan 2006', times of day (14:30, 2:30pm, noon, midnight) with UTC, Z or a numeric offset, weekdays ('next friday', 'last monday') and relative items ('3 days ago', '+2 hours', 'next month', 'fortnight'), combined as in '2026-01-31 +1 month' or 'tomorrow 09:00'. Anything else is reported as an invalid date, where GNU's grammar is larger still. -f FILE prints one date per line of FILE (- for standard input) and -r FILE the last modification time of FILE. gnux never changes system settings, so -s and a MMDDhhmm[[CC]YY][.ss] operand fail with 'cannot set date: Operation not supported'. --resolution prints the resolution of the system clock, measured as GNU measures it, as a time that many seconds after the epoch (0.000000001 for a nanosecond clock), and in any format '%-N' prints as many digits of nanoseconds as that resolution needs. --debug is not implemented.
gnux's terminal view (BR-13), on a terminal (--pretty=auto, the default, or GNUX_PRETTY), one date is a panel titled with it in the format asked for, holding the same moment as local time, UTC, ISO 8601 and Unix seconds, its day of the year and week, its zone, and how far it is from now. $(datex) and datex > FILE are a pipe and a file, not a terminal, so a script still gets GNU's one line; -f's lines are GNU's. --theme=NAME picks its colors.
Permissions
Printing needs no permissions; -f needs read permission on FILE and -r search permission on the directories leading to it.
Use cases
- Timestamping file names, log lines and backups.
- Converting between epoch seconds and readable dates.
- Computing dates relative to now or to another
date, such as 'next friday'. - Printing machine-readable ISO 8601 or RFC 3339 timestamps.
- Showing the current time in another zone with TZ or
-u.
Flags
-d, --date STRING display time described by STRING, not 'now'
-f, --file DATEFILE like --date; once for each line of DATEFILE
--help display this help and exit
-I, --iso-8601 FMT[="date"] output date/time in ISO 8601 format. FMT='date' for date only (the default), 'hours', 'minutes', 'seconds', or 'ns'
--pretty WHEN[="always"] the gnux terminal view WHEN: 'always' (the default when WHEN is omitted), 'auto' (the default: on a terminal only), or 'never'; GNUX_PRETTY sets the default
-r, --reference FILE display the last modification time of FILE
--resolution output the available resolution of timestamps
--rfc-3339 FMT output date/time in RFC 3339 format. FMT='date', 'seconds', or 'ns'
-R, --rfc-email output date and time in RFC 5322 format
-s, --set STRING set time described by STRING (not supported)
--theme NAME color the view with the built-in theme NAME (gnux theme picks and saves one); GNUX_THEME sets the default
--universal same as --utc
-u, --utc print or set Coordinated Universal Time (UTC)
--version output version information and exitExamples
Check the date and time on a server
datexGet today's date in a sortable form for a file name
datex -IStamp a log line with a precise, sortable time
datex -IsecondsCheck UTC when coordinating with people in other time zones
datex -uPrint the time the way your report needs it
datex '+%Y-%m-%d %H:%M:%S'Name tonight's database backup after today's date
cpx db.sqlite "db-$(datex +%F).sqlite"Get a Unix timestamp to store or compare
datex +%sRead a Unix timestamp you found in a log or a database
datex -u -d @1700000000Find the date three days ago, to clean up older files
datex -d '3 days ago' +%FFind the date of next Friday for a deadline
datex -d 'next friday' +%A,%FSee when a report was last saved
datex -r report.txtSee what time it is in Tokyo before calling a colleague
TZ=Asia/Tokyo datexProduce a timestamp an API expects in RFC 3339
datex --rfc-3339=secondsConvert a column of dates into timestamps for sorting
datex -f dates.txt +%sTimestamp a log line in the portable gnux shell, the same on every OS
gnux shell -c 'datex -Iseconds >> run.log'Check how finely this system's clock measures time
datex --resolutionTimestamp a log line to the clock's own precision
datex '+%H:%M:%S.%-N build started'Options
Each option has a page of its own, with its usage and examples.
- -d, --date: Display time described by STRING, not 'now'.
- -f, --file: Like --
date; once for each line of DATEFILE. - -I, --iso-8601: Output
date/time in ISO 8601 format. FMT='date' fordateonly (the default), 'hours', 'minutes', 'seconds', or 'ns'. - --pretty: The
gnuxterminal view WHEN: 'always' (the default when WHEN is omitted), 'auto' (the default: on a terminal only), or 'never'; GNUX_PRETTY sets the default. - -r, --reference: Display the last modification time of FILE.
- --resolution: Output the available resolution of timestamps.
- --rfc-3339: Output
date/time in RFC 3339 format. FMT='date', 'seconds', or 'ns'. - -R, --rfc-email: Output
dateand time in RFC 5322 format. - -s, --set: Set time described by STRING (not supported).
- --theme: Color the view with the built-in theme NAME (
gnuxtheme picks and saves one); GNUX_THEME sets the default. - --universal: Same as
--utc. - -u, --utc: Print or set Coordinated Universal Time (UTC).
Exit status
| Status | Meaning |
|---|---|
| 0 | success: every operand was processed |
| 1 | failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake |
Help in the terminal
datex --help # options, first examples, exit status
gnux help datex # this page: the full manual
gnux help datex --OPTION # one option in depth, with its examples