I'm having an interesting issue with date command in my script. My script generates loads of hourly data form a given date range. I use date function to increase "from" date by an hour till it hits "to" date. The date method works just fine and increased the "from" date by an hour as I expected. However, it stops increasing once it reaches 2017/11/05 01:00:00. I haven't tested whole lot of dates yet, but the other date that has the same issue is 2016/11/06 01:00:00.

$ date -d "2017/11/05 01:00:00 1 hour" +"%Y/%m/%d %T"
2017/11/05 01:00:00

$ date -d "2016/11/06 01:00:00 1 hour" +"%Y/%m/%d %T"
2016/11/06 01:00:00

Linux version Linux 3.10.0-229.4.2.el7.x86_64

  • I don't have that issue. (date (GNU coreutils) 8.25)
    – pLumo
    Oct 11 '18 at 14:50
  • I tried the same thing under git bash and cygwin (CYGWIN_NT-10.0-WOW 703CSQ2 1.7.35(0.287/5/3) ) and I'm still getting the same issue.
    – KMC
    Oct 11 '18 at 14:54
  • @RoVo are you from non daylight saving country?
    – KMC
    Oct 11 '18 at 15:06
  • You can help answerers by adding a %z to both format strings and editing the consequent output into the question.
    – JdeBP
    Oct 11 '18 at 18:03

Turns out, it's DST (Daylight saving time) causing this issue. When I pass DST date 1 am (First Sunday of November) to date command, it probably increases the date by an hour internally and deduct one hour from it for DST. Solution is to use -u (UTC) as suggested by @jkan5855.

$ date -d "2017/11/05 01:00:00 1 hour" +"%Y/%m/%d %T" -u

Try doing date --version to see which version of date you're flying with. The command on date (GNU Coreutils) 8.30 works fine

Reinstall or update GNU Coreutils (find the appropriate package for your linux/subsystem), as nobody else is getting this issue apparently. Your exact command prints out 2017/11/05 02:00:00 for me.

If that doesn't fix it, is your computer temporarily date-impaired. I have no better way of describing it, but try restarting your computer, since you're also getting this on other subsystems/terminals.

  • are you happen to be in a location where DST doesn't apply?
    – KMC
    Oct 11 '18 at 15:04
  • No, I'm in Eastern European Summer Time right now, so it definitively does apply. Are you in Canada, cuba, haiti or other country where DST ended 11-05 in 2017?
    – jkan5855
    Oct 11 '18 at 15:07
  • Definitely it caused by DST. Because all the dates I'm having issue with coincide with DST date (First sunday of November)
    – KMC
    Oct 11 '18 at 15:13
  • alright. run date --version and give me the output
    – jkan5855
    Oct 11 '18 at 15:14
  • 1
    For some reason I don't get the same result when using my DST date and time. Try doing all the dates with -u and repeat the hour twice near DST as clocks are turned 1 hour backwards so the clock goes 23 0 1 1 2 3 4 with double ones
    – jkan5855
    Oct 11 '18 at 15:22

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.