0

I have followed examples on numerous stack exchange websites and various other tutorial websites on how to do date math. I have tried linux (on containers) I get the exact same error:

$ docker run -it bash date -d '2014-11-19T15:40:30+10d'
date: invalid date '2014-11-19T15:40:30+10d'
bash-5.0# date -d  '+10 days'
date: invalid date '+10 days'
bash-5.0# date -d  '+10 d'
date: invalid date '+10 d'
bash-5.0# date -d  '2014-11-19T15:40:30+10 d'
date: invalid date '2014-11-19T15:40:30+10 d'
bash-5.0# date -d  '2014-11-19T15:40:30+10 days'
date: invalid date '2014-11-19T15:40:30+10 days'
bash-5.0# date -d  '2014-11-19T15:40:30 +10 days'
date: invalid date '2014-11-19T15:40:30 +10 days'
bash-5.0# date -d  '2014-11-19T15:40:30 +10 d'
date: invalid date '2014-11-19T15:40:30 +10 d'

bash version:

$ docker run -it bash bash --version
GNU bash, version 5.0.2(1)-release (x86_64-pc-linux-musl)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

I've tried this post This post and this post and even this random website

They can't all be wrong.

  • I tried all the combinations including yours. Updated the example. You can run the command yourself to try: docker run -it bash date -d '2014-11-19T15:40:30+10d' – Christian Bongiorno Feb 13 '19 at 03:49
  • 2
    @ChristianBongiorno +10 days as @steeldriver suggested works for me. What does your date --version say? – undercat Feb 13 '19 at 04:36
  • 4
    Bash isn't involved in the error. – Ed Grimm Feb 13 '19 at 04:37
  • For me, date -d '2014-11-19T15:40:30 10 days' works, date -d '10 days' works, date -d '+10 days' works, but date -d '2014-11-19T15:40:30 +10 days' gives me the same thing asdate -d '2014-11-19T15:40:30 9 hours'. I'm not sure why. My date --version is 8.29. – Ed Grimm Feb 13 '19 at 04:45

1 Answers1

12
$ docker run bash date --version
BusyBox v1.29.3 (2019-01-24 07:45:07 UTC) multi-call binary.
...

You are using the BusyBox version of date which is not fully compatible with the Coreutils version that can be found on most desktop Linux distros. Quoting BusyBox's man page:

Recognized TIME formats:

hh:mm[:ss]
[YYYY.]MM.DD-hh:mm[:ss]
YYYY-MM-DD hh:mm[:ss]
[[[[[YY]YY]MM]DD]hh]mm[.ss]
'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead

Your possible options are:

  • Use the BusyBox-exclusive -D key (e.g. busybox date -D +10days) which has extended support for time expressions similar to what Coreutils date -d has. Note that the option will not be recognized by the Coreutils date.
  • Make do with the BusyBox syntax supported by both implementations.
  • Install Coreutils in your Docker container.
  • Use an existing container that has Coreutils.
undercat
  • 1,857
  • I had just assumed that, date being as old as Earth, it would have identical support/functionality even on an alpine build. – Christian Bongiorno Feb 13 '19 at 17:38
  • 1
    It's even "worse" than that, BSD has its own version of date which is also different! I don't have much experience writing portable code on UNIX, but it seems you either have to target one specific flavour (for Linux, targeting GNU Coreutils should make most sense due to its relative ubiquity and user friendliness), or use the POSIX subset of functionality exclusively, hoping it would be supported by all implementations. – undercat Feb 13 '19 at 20:01