UNCLASSIFIED - NON CLASSIFIÉ Good day,
I noticed this behaviour of the "date" command today, and perhaps it is a bug, or it's by design. Running date -date="-5 days 4 hours" produces the date minus 5 days from now plus 4 hours, whereas the intent is more likely to be "-5 days and 4 hours". I tried it with other numbers of days and hours and observed the same behaviour. Running date -date="-5 days -4 hours" produces the expected time. I tried this using GNU date on the following systems: Oracle Linux 9 on WSL on Windows 11, Ubuntu 24.04 on WSL on Windows 11, CentOS 9, RHEL 7.9 Here is the output of one sample. The coloration is mine. $ date --date='-5 days 4 hours' --debug date: parsed relative part: -5 day(s) date: parsed relative part: -5 day(s) +4 hour(s) date: input timezone: system default date: using current time as starting value: '15:18:38' date: using current date as starting value: '(Y-M-D) 2026-03-17' date: starting date/time: '(Y-M-D) 2026-03-17 15:18:38' date: warning: when adding relative days, it is recommended to specify noon date: after date adjustment (+0 years, +0 months, -5 days), date: new date/time = '(Y-M-D) 2026-03-12 15:18:38' date: '(Y-M-D) 2026-03-12 15:18:38' = 1773343118 epoch-seconds date: after time adjustment (+4 hours, +0 minutes, +0 seconds, +0 ns), date: new time = 1773357518 epoch-seconds date: timezone: system default date: final: 1773357518.401888226 (epoch-seconds) date: final: (Y-M-D) 2026-03-12 23:18:38 (UTC) date: final: (Y-M-D) 2026-03-12 19:18:38 (UTC-04) The components of the -date= string are parsed individually rather than semantically (as spoken) and perhaps this is the intent and that's how most users use it and this is a non-issue. I wanted to bring it up just in case. Thank you, Khalil Hayek (he, il) Manager, Line-of-business Applications Management, Surveyor General Branch, Natural Resources Canada Chef, Gestion des applications dédiées aux lignes d'affaires, Direction de l'arpenteur général, Ressources naturelles Canada [email protected]<mailto:[email protected]> / Tél. 613-219-9418 / 613-350-6083 N'hésitez pas à me répondre dans la langue officielle de votre choix. / Please feel free to reply in the official language of your choice.
