DATEDIFF(1)
πΈ datediff(1) πΈ
okay bestie, buckle up β this is the manual page for datediff, and it's literally about computing a duration from a DATE/TIME (the reference date/time) to the other date/time(s) you throw at it. group-chat energy only, but the facts stay exactly where they belong. π
π NAME π
datediff β compute duration from DATE/TIME (the reference date/time) to the other π«
π¦ SYNOPSIS π¦
datediff [OPTION]... DATE/TIME [DATE/TIME]...
β¨ DESCRIPTION β¨
So datediff computes the duration from DATE/TIME (that's the reference date/time, the main character) to the other DATE/TIMEs you give it, and then prints the result as a duration. If you don't give the other DATE/TIMEs, it reads them from stdin. no cap. π«Ά
DATE/TIME can also be one of these specials:
nowβ interpreted as the current (UTC) time stamptimeβ the time part of the current (UTC) time stamptodayβ the current date (according to UTC)tomo[rrow]β tomorrow's date (according to UTC)y[ester]dayβ yesterday's date (according to UTC)
π‘ Note: the output format of durations (the one you set with-f) takes all the format specifiers into account. So if you specify%Mand%S, for example, it prints the duration in minutes and seconds; if you specify%Sonly, it prints the duration in seconds. iykyk.
See section The refinement rule in ddiff(1).
π OPTIONS π
π Recognized OPTIONs π
-h,--helpβ print help and exit. iconic behavior.-V,--versionβ print version and exit. slay.-q,--quietβ suppress the message about date/time and duration parser errors and fix-ups. The default is to print a warning or the fixed-up value and return error code2. Also see-S/--skip-illegalto output an empty line instead of leaving out the line altogether. lowkey important.-S,--skip-illegalβ deprecated, use-E/--empty-mode. π¨ yes, deprecated, bestie, don't build your whole vibe on it.-E,--empty-modeβ output empty lines as a placeholder for illegal input, i.e. parser errors or date/times that cannot be subtracted.-f,--format=STRINGβ output format. This can either be a specifier string (similar tostrftime()'sFMT) or the name of a calendar. choose your fighter.-i,--input-format=STRING...β input format, can be used multiple times. Each date/time will be passed to the input format parsers in the order they are given; if a date/time can be read successfully with a given input format specifier string, that value will be used. order matters, periodt.-b,--base=DTβ for underspecified input useDTas a fallback to fill in missing fields. Also used for ambiguous format specifiers to position their range on the absolute time line. Must be a date/time in ISO8601 format. If omitted, defaults to the current date/time.-e,--backslash-escapesβ enable interpretation of backslash escapes in the output and input format specifier strings. fancy.--from-locale=LOCALEβ interpret dates on stdin or the command line as coming from the localeLOCALE. This would only affect month and weekday names, as input formats have to be specified explicitly.--from-zone=ZONEβ interpret dates on stdin or the command line as coming from the time zoneZONE. timezone queen behavior.
π FORMAT SPECS π
Format specs in dateutils are similar to posix' strftime(). cute.
However, due to a broader range of supported calendars, dateutils must employ different rules. it's giving "we had to switch it up." π
π 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 (range00to05)%Cβ the count of the weekday within the year (range00to53)%dβ the day of the month, 2 digits (range00to31)%Dβ the day of the year, 3 digits (range000to366)%Fβ equivalent to%Y-%m-%d(ymd's canonical format)%gβ ISO week date year without the century (range00to99)%Gβ ISO week date year including the century%jβ equivalent to%D%mβ the month in the current calendar (range00to12)%Qβ the quarter of the year (rangeQ1toQ4)%qβ the number of the quarter (range01to04)%sβ the number of seconds since the Epoch.%uβ the weekday as number (range01to07, Sunday being07)%Uβ the week count, day of week is Sun (range00to53)%Vβ the ISO week count, day of week is Mon (range01to53)%wβ the weekday as number (range00to06, Sunday being00)%Wβ the week count, day of week is Mon (range00to53)%yβ the year without a century (range00to99)%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)
also these roman-numeral cuties:
%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
and these calendar-specific ones:
%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.
ordinal girlies:
%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.
business-day behavior:
%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 (range00to23)%Iβ the hour of the day using a 12h clock, 2 digits (range01to12)%Mβ the minute (range00to59)%Nβ the nanoseconds (range000000000to999999999)%pβ the stringAMorPM, noon isPMand midnight isAM.%Pβ like%pbut in lowercase%Sβ the seconds (range00to60, and60is 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 altogetherthβ suffix, read and print ordinal numbersbβ suffix, treat days as business days
π¨ By design dates before 1601-01-01 are not supported. like, not even a little bit.
For conformity, here is a list of calendar designators and their corresponding format string:
ymdβ%Y-%m-%dymcwβ%Y-%m-%c-%wywdβ%rY-W%V-%ubizdaβ%Y-%m-%dblilianβn/aldnβn/ajulianβn/ajdnβn/amatlabβn/amdnβ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.
π FORMAT SPECS FOR DURATIONS π
Unlike time or absolute instants, durations are reference-free, i.e. the reference instant is not part of the duration. As a result, durations cannot be named, i.e. there is no naming scheme that applies to all durations and all references unambiguously. it's giving "no labels, just vibes." π
Consequently, none of the format specifiers for date/times makes sense for durations in the literal sense. However, to aid intuitive usage, we reused format specifiers when they represent integral values and a valid unit for duration, as follows:
π Date specs
%cβ equivalent to%w%dβ duration in days%Fβ equivalent to%ddwith no resorting to bigger units%mβ duration in months%wβ duration in weeks%yβ equivalent to%Y%Yβ duration in years%dbβ duration in business days%dBβ equivalent to%db
β° Time specs
%Hβ duration in hours%Iβ equivalent to%H%Mβ duration in minutes%Sβ duration in seconds%Tβ equivalent to%Sswithout resorting to bigger units%rSβ duration in real-life seconds, as in including leap seconds%rTβ equivalent to%rSswithout resorting to bigger units
π§ General specs
%nβ a newline character%tβ a tab character%%β a literal%character
π Modifiers
%rβ modifier to turn units into real units%0β modifier to pad refined values with zeroes%SPCβ modifier to pad refined values with spacesbβ suffix, treat days as business days
π THE REFINEMENT RULE π
Durations are somewhat ambiguous when it comes to representing them through format specifiers. Unlike format specifiers in point-in-time representations, duration specifiers can have an intra-line relationship. messy, but we move. π
So for instance, a duration of 128 seconds might be presented through "%S" as "128" but similarly through "%M:%S" as "02:08" (read two minutes and 8 seconds). see? cute.
There are several approaches to dealing with this ambiguity. The ddiff tool will follow what we call the refinement rule. That is, regardless of the position of a format specifier, if it is a valid refinement of another specifier in the format string, then it will only show the fractional value, i.e. the value in its natural range with respect to the refined specifier. no cap.
%Yβ possible refinements:%m,%w,%d%mβ possible refinements:%w,%d%wβ possible refinements:%d%dβ possible refinements:%H,%M,%S%Hβ possible refinements:%M,%S%Mβ possible refinements:%S
The refinement alternatives are listed in order of precedence and they are mutually exclusive. I.e. it is not possible to express a duration in months and hours without having a "%d" specifier as well. On the other hand, in a chain of refinements, inner elements are optional, i.e. you can express a duration in weeks and hours because every day has 24 hours and hence there are 168 hours in a week. math ate. π₯
In case of negative durations (the minuend is in the future relative to the subtrahend), only the largest unit will carry the minus sign.
Using the refinement rule keeps the format string dead simple β there's no need for operators or a full-blown language to distinguish the range ambiguity, which then would have to be escaped because they could also in theory be part of the literal characters of the format string. That whole mess results more often than not in command lines that are hard to craft and even harder to understand later on (e.g. if used in shell scripts). literally the worst.
The refinement rule ingeniously covers the 99% case but, unlike other approaches, there's no way to display two unrefined values in the same format string, e.g. "'%w weeks (which is %d days)'". π
β¨ EXAMPLES β¨
okay bestie this is the fun part β real commands, real outputs, no cap π every single one is here, exactly as it'll look in your terminal π«Ά
Same day? Zero. Obviously. β¨
$ ddiff 2012-03-02 2012-03-02
0
$
Ten days apart in March π
$ ddiff 2012-03-02 2012-03-12
10
$
Crossing into April, so it's 41 days π
$ ddiff 2012-03-02 2012-04-12
41
$
March 12 β April 2, that's 21 πΈ
$ ddiff 2012-03-12 2012-04-02
21
$
Flip the order and it just goes negative, she's consistent like that π
$ ddiff 2012-04-02 2012-03-12
-21
$
Now with a format spec β %dd gives you days with a cute little d glued on π
$ ddiff 2012-01-02 2012-02-29 -f '%dd'
58d
$
Stack two specs and you get weeks and days, iconic combo β¨
$ ddiff 2012-01-02 2012-02-29 -f '%ww %dd'
8w 2d
$
Times work too, same energy π
$ ddiff 10:00:00 10:00:00
0s
$
$ ddiff 10:01:00 10:06:00
300s
$
$ ddiff 10:06:00 10:01:00
-300s
$
%S = seconds, and yes you can put literal words around it π₯
$ ddiff 10:01:00 11:03:10 -f '%S sec'
3730 sec
$
Minutes and seconds together, slay π
$ ddiff 10:01:00 11:03:10 -f '%Mm %Ss'
62m 10s
$
Classic %H:%M:%S giving clock vibes β and notice there's no zero-padding, so it's 1:2:10 not 01:02:10, lowkey a whole look π
$ ddiff 10:01:00 11:03:10 -f '%H:%M:%S'
1:2:10
$
Full timestamps? Yeah she eats those for breakfast π
$ ddiff 2012-03-02T10:04:00 2012-03-02T10:14:00
600s
$
$ ddiff 2012-03-02T10:04:00 2012-03-02T10:14:00 -f '%M min'
10 min
$
Big ol' gap across two days π¦
$ ddiff 2012-03-01T12:17:00 2012-03-02T14:00:00
92580s
$
And the same gap dressed up all fancy β mixing days and seconds in one format string, main character energy fr fr π
$ ddiff 2012-03-01T12:17:00 2012-03-02T14:00:00 -f '%d days and %S seconds'
1 days and 6180 seconds
$
π AUTHOR π
Written by Sebastian Freundt <freundt@fresse.org> β king behavior, we stan π
π REPORTING BUGS π
Found a bug? Report it, bestie, don't just suffer in silence π
Report bugs to: https://github.com/hroptatyr/dateutils/issues
π SEE ALSO π
The full documentation for datediff is maintained as a Texinfo manual π if the info and datediff programs are properly installed at your site, this command
info (dateutils)datediff
should give you access to the complete manual β¨ go read it, it's giving thorough π«Ά
okay that's the whole page bestie, you're officially a datediff expert π β¨
this beauty's from dateutils 0.4.11, dated January 2024, and it's page DATEDIFF(1) β go forth and diff some dates ππ
π¦ where this page comes from
- alpine 3.24: dateutils-doc 0.4.11-r0 Β· BSD-3-Clause
- nixos 26.05: dateutils 0.4.11
- nixpkgs unstable: dateutils 0.4.11
- opensuse-leap 16.0: dateutils 0.4.11-bp160.1.17 Β· BSD-3-Clause
- opensuse-leap 16.0: dateutils 0.4.11-bp160.1.17 Β· BSD-3-Clause
- opensuse-leap 16.0: dateutils 0.4.11-bp160.1.17 Β· BSD-3-Clause
- opensuse-leap 16.0: dateutils 0.4.11-bp160.1.17 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms