DATESORT(1)

πŸ“¦
version 0.4.11 Β· 5 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– datesort(1) β€” the manual, but make it a group chat πŸ’–

okay bestie, so datesort is a User Command and this whole page is basically me explaining it to you while we're both supposed to be doing something else. no cap, it's a good one. stay with me 🫢


✨ NAME ✨

datesort β€” sort the contents of FILE chronologically. that's it. that's the whole job. iconic behavior honestly πŸ‘‘


✨ SYNOPSIS ✨

datesort [OPTION]...  [FILE]...

✨ DESCRIPTION ✨

Sort the contents of FILE chronologically. If you don't give it a FILE, it literally just reads from stdin, no big deal πŸ™ˆ

The first date/time value on each line is the sort key. one per line, first one wins, periodt.

now here's the ranking drama you need to know, because the ordering rules are lowkey specific:

  • Dates that have no time count as a smaller value than any date/time on the same day.
  • Times that have no date count as a smaller value than any date or date/time.
  • If a line has no dates, times, or date/times at all, it gets sorted towards the front. yes bestie, the dateless lines are first in line πŸ’…

Here are the recognized OPTIONs:

  • -h, --help β€” print help and exit ✨
  • -V, --version β€” print version and exit
  • -i, --input-format=STRING... β€” the input format. you can pass this multiple times and it's giving very thorough. Each date/time gets handed to the input format parsers in the order you gave them, and if a date/time can be read successfully with a given input format specifier string, that value is the one that gets used 🎯
  • -b, --base=DT β€” for underspecified input, use DT as a fallback to fill in the missing fields. it's also used for ambiguous format specifiers, to position their range on the absolute time line. it must be a date/time in ISO8601 format. if you omit it, it defaults to the current date/time ⏰
  • -e, --backslash-escapes β€” turn on interpretation of backslash escapes in the input format specifier strings πŸͺ„
  • --from-locale=LOCALE β€” interpret dates on stdin or on the command line as coming from the locale LOCALE. ngl this would only affect month and weekday names, because input formats have to be specified explicitly anyway 🌍
  • --from-zone=ZONE β€” interpret dates on stdin or the command line as coming from the time zone ZONE πŸ•°οΈ
  • -r, --reverse β€” flip the sort order. chaos mode, but make it chronological-backwards πŸ”„
  • -u, --unique β€” print at most one line per date/time value. no duplicates, we're keeping it exclusive πŸ’…

✨ FORMAT SPECS ✨

Format specs in dateutils are similar to posix' strftime().

BUT β€” and this is the plot twist β€” because dateutils supports a broader range of calendars, it has to employ different rules. so don't come at it expecting strftime to carry you, bestie 😭

πŸŽ€ Date specs:

  • %a β€” the abbreviated weekday name
  • %A β€” the full weekday name
  • %_a β€” the weekday name shortened to a single character (MTWRFAS)
  • %b β€” the abbreviated month name
  • %B β€” the full month name
  • %_b β€” the month name shortened to a single character (FGHJKMNQUVXZ)
  • %c β€” the count of the weekday within the month (range 00 to 05)
  • %C β€” the count of the weekday within the year (range 00 to 53)
  • %d β€” the day of the month, 2 digits (range 00 to 31)
  • %D β€” the day of the year, 3 digits (range 000 to 366)
  • %F β€” equivalent to %Y-%m-%d (ymd's canonical format)
  • %g β€” ISO week date year without the century (range 00 to 99)
  • %G β€” ISO week date year including the century
  • %j β€” equivalent to %D
  • %m β€” the month in the current calendar (range 00 to 12)
  • %Q β€” the quarter of the year (range Q1 to Q4)
  • %q β€” the number of the quarter (range 01 to 04)
  • %s β€” the number of seconds since the Epoch.
  • %u β€” the weekday as number (range 01 to 07, Sunday being 07)
  • %U β€” the week count, day of week is Sun (range 00 to 53)
  • %V β€” the ISO week count, day of week is Mon (range 01 to 53)
  • %w β€” the weekday as number (range 00 to 06, Sunday being 00)
  • %W β€” the week count, day of week is Mon (range 00 to 53)
  • %y β€” the year without a century (range 00 to 99)
  • %Y β€” the year including the century
  • %_y β€” the year shortened to a single digit
  • %Z β€” the zone offset in hours and minutes (HH:MM) with a preceding sign (+ for offsets east of UTC, - for offsets west of UTC)
  • %Od β€” the day as roman numerals
  • %Om β€” the month as roman numerals
  • %Oy β€” the two digit year as roman numerals
  • %OY β€” the year including the century as roman numerals
  • %rs β€” in time systems whose Epoch is different from the unix Epoch, this selects the number of seconds since then.
  • %rY β€” in calendars with years that don't coincide with the Gregorian years, this selects the calendar's year.
  • %dth β€” the day of the month as an ordinal number, 1st, 2nd, 3rd, etc.
  • %mth β€” the month of the year as an ordinal number, 1st, 2nd, 3rd, etc.
  • %db β€” the business day of the month (since last month's ultimo)
  • %dB β€” number of business days until this month's ultimo

πŸŽ€ Time specs:

  • %H β€” the hour of the day using a 24h clock, 2 digits (range 00 to 23)
  • %I β€” the hour of the day using a 12h clock, 2 digits (range 01 to 12)
  • %M β€” the minute (range 00 to 59)
  • %N β€” the nanoseconds (range 000000000 to 999999999)
  • %p β€” the string AM or PM, noon is PM and midnight is AM.
  • %P β€” like %p but in lowercase
  • %S β€” the seconds (range 00 to 60, 60 is for leap seconds)
  • %T β€” equivalent to %H:%M:%S

πŸŽ€ General specs:

  • %n β€” a newline character
  • %t β€” a tab character
  • %% β€” a literal % character

πŸŽ€ Modifiers:

  • %O β€” modifier to turn decimal numbers into Roman numerals
  • %r β€” modifier to turn units into real units
  • %0 β€” modifier to turn on zero prefixes
  • %SPC β€” modifier to turn on space prefixes
  • %- β€” modifier to turn off prefixes altogether
  • th β€” suffix, read and print ordinal numbers
  • b β€” suffix, treat days as business days
⚠️ and this one is important fr fr: by design, dates before 1601-01-01 are not supported. do not come for it, it simply will not do it πŸ’€

For conformity, here is a list of calendar designators and their corresponding format string:

  • ymd β€” %Y-%m-%d
  • ymcw β€” %Y-%m-%c-%w
  • ywd β€” %rY-W%V-%u
  • bizda β€” %Y-%m-%db
  • lilian β€” n/a
  • ldn β€” n/a
  • julian β€” n/a
  • jdn β€” n/a
  • matlab β€” n/a
  • mdn β€” n/a

These designators can be used as output format string, and moreover, @code{lilian}/@code{ldn} and @code{julian}/@code{jdn} can also be used as input format string. slay ✨


✨ EXAMPLES ✨

reading from stdin, iconic:

$ datesort < "$@{srcdir@}/caev_01.txt"
2009-06-03 caev="DVCA" secu="VOD" exch="XLON" xdte="2009-06-03" nett/GBX="5.2"
2010-11-17 caev="DVCA" secu="VOD" exch="XLON" xdte="2010-11-17" nett/GBX="2.85"
2011-11-16 caev="DVCA" secu="VOD" exch="XLON" xdte="2011-11-16" nett/GBX="3.05"
2012-06-06 caev="DVCA" secu="VOD" exch="XLON" xdte="2012-06-06" nett/GBX="6.47"
2013-06-12 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-06-12" nett/GBX="6.92"
2013-11-20 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-11-20" nett/GBX="3.53"
$

and now passing the file as an argument, same energy, same output 🫢:

$ datesort "$@{srcdir@}/caev_01.txt"
2009-06-03 caev="DVCA" secu="VOD" exch="XLON" xdte="2009-06-03" nett/GBX="5.2"
2010-11-17 caev="DVCA" secu="VOD" exch="XLON" xdte="2010-11-17" nett/GBX="2.85"
2011-11-16 caev="DVCA" secu="VOD" exch="XLON" xdte="2011-11-16" nett/GBX="3.05"
2012-06-06 caev="DVCA" secu="VOD" exch="XLON" xdte="2012-06-06" nett/GBX="6.47"
2013-06-12 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-06-12" nett/GBX="6.92"
2013-11-20 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-11-20" nett/GBX="3.53"
$

now -r, the reverse girlies:

$ datesort -r < "$@{srcdir@}/caev_01.txt"
2013-11-20 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-11-20" nett/GBX="3.53"
2013-06-12 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-06-12" nett/GBX="6.92"
2012-06-06 caev="DVCA" secu="VOD" exch="XLON" xdte="2012-06-06" nett/GBX="6.47"
2011-11-16 caev="DVCA" secu="VOD" exch="XLON" xdte="2011-11-16" nett/GBX="3.05"
2010-11-17 caev="DVCA" secu="VOD" exch="XLON" xdte="2010-11-17" nett/GBX="2.85"
2009-06-03 caev="DVCA" secu="VOD" exch="XLON" xdte="2009-06-03" nett/GBX="5.2"
$

same thing but with the file argument:

$ datesort -r "$@{srcdir@}/caev_01.txt"
2013-11-20 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-11-20" nett/GBX="3.53"
2013-06-12 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-06-12" nett/GBX="6.92"
2012-06-06 caev="DVCA" secu="VOD" exch="XLON" xdte="2012-06-06" nett/GBX="6.47"
2011-11-16 caev="DVCA" secu="VOD" exch="XLON" xdte="2011-11-16" nett/GBX="3.05"
2010-11-17 caev="DVCA" secu="VOD" exch="XLON" xdte="2010-11-17" nett/GBX="2.85"
2009-06-03 caev="DVCA" secu="VOD" exch="XLON" xdte="2009-06-03" nett/GBX="5.2"
$

and -u, where we keep it exclusive and only print one line per date/time value πŸ’…:

$ datesort -u < "$@{srcdir@}/caev_02.txt"
2009-06-03 caev="DVCA" secu="VOD" exch="XLON" xdte="2009-06-03" nett/GBX="5.2"
2010-11-17 caev="XXXX" secu="VOD" exch="XLON" xdte="2010-11-17"
2011-11-16 caev="DVCA" secu="VOD" exch="XLON" xdte="2011-11-16" nett/GBX="3.05"
2012-06-06 caev="DVCA" secu="VOD" exch="XLON" xdte="2012-06-06" nett/GBX="6.47"
2013-06-12 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-06-12" nett/GBX="6.92"
2013-11-20 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-11-20" nett/GBX="3.53"
$

aaaand once more with the file argument, because consistency is the whole vibe:

$ datesort -u "$@{srcdir@}/caev_02.txt"
2009-06-03 caev="DVCA" secu="VOD" exch="XLON" xdte="2009-06-03" nett/GBX="5.2"
2010-11-17 caev="XXXX" secu="VOD" exch="XLON" xdte="2010-11-17"
2011-11-16 caev="DVCA" secu="VOD" exch="XLON" xdte="2011-11-16" nett/GBX="3.05"
2012-06-06 caev="DVCA" secu="VOD" exch="XLON" xdte="2012-06-06" nett/GBX="6.47"
2013-06-12 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-06-12" nett/GBX="6.92"
2013-11-20 caev="DVCA" secu="VOD" exch="XLON" xdte="2013-11-20" nett/GBX="3.53"
$

✨ AUTHOR ✨

Written by Sebastian Freundt <freundt@fresse.org> πŸ’œ


✨ REPORTING BUGS ✨

Report bugs to: https://github.com/hroptatyr/dateutils/issues

(be nice, bestie, they're doing their best 🫢)


✨ SEE ALSO ✨

The full documentation for datesort is maintained as a Texinfo manual. If the info and datesort programs are properly installed at your site, the command

info (dateutils)datesort

should give you access to the complete manual. iykyk πŸ¦‹


okay that's the whole page, thank you for coming to my ted talk 🌸

this was dateutils 0.4.11, dated November 2025 β€” DATESORT(1) and out, love u, bye πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from