I have come across this weird behaviour of GNU date.

date -d "29-May-20 09:29 1 minute" +"%d-%b-%y %H:%M" 

gives output: 29-May-20 09:30 --> Note: I have given here the abbreviated month name format specifier '%b'


date -d "29-05-20 09:29 1 minute" +"%d-%m-%y %H:%M"

gives output: 20-05-29 09:30 --> I mean the year and the date field is jumbled, though I have given the correct format specifier '%m' for the month field. How to make it work to give the expected output 29-05-20?

  • 1
    Read carefully about how GNU date parses user input: gnu.org/software/coreutils/manual/html_node/… => "For numeric months, the ISO 8601 format ‘year-month-day’ is allowed, where year is any positive number, month is a number between 01 and 12, and day is a number between 01 and 31. " Jan 21, 2021 at 20:09

1 Answer 1


The +FORMAT describes the output, not how the argument to -d is parsed. If you want to ensure that is parsed the way you want, you should feed it an unambiguous representation

  • Fox then it should be dd-mm-yy right? according to the format specifier "%d-%m-%y" but I am getting the yy-mm-dd as output Jan 21, 2021 at 9:07
  • not at all. let me rephrase: the format specifier has absolutely nothing to do with that argument. The fully-numeric date you've given is assumed to by yy-mm-dd (if possible), and is then output according to the format specifier, which has the dd part and the yy part in the opposite order
    – Fox
    Jan 21, 2021 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.