In one of my script, I need to find a 2 days back date from a given date. I have been using the below without any issue since long time, but it's just the first time I got a error which drilled down to wrong value by date command.

$ date -d 20140331" - 2 days" +%Y%m%d

Expected output


Actual output


Using "- 2 days" gives expected output, but still struggling to find why subtracting seconds didn't work?

unix date output

Note: My process runs in middle of the day, and hence I don't see any extreme boundary condition like 1 sec got dwindled here and there.

Some more info

$ date --version
date (GNU coreutils) 5.97
Copyright (C) 2006 Free Software Foundation, Inc.
  • That is strange. When I run date -d 20140331" - 172800 seconds" +%Y%m%d I get 20140329. @manatwork Lol no. This is a whole day (look at the numbers closely)!
    – goldilocks
    Mar 31, 2014 at 13:16
  • 3
    In Europe at least, 48 hours before 2014-03-31 00:00:00 was 2014-03-28 23:00:00 because of the summer time switch. Mar 31, 2014 at 13:28
  • 1
    What timezone are you/your server in? This could be a daylight savings time issue.
    – Josh Jolly
    Mar 31, 2014 at 13:28
  • @Josh, the server time is in BST.
    – mtk
    Mar 31, 2014 at 13:34
  • Seems got the issue.. THE DST change for london was on 30 Mar, hence the expected difference. timeanddate.com/time/change/uk/london
    – mtk
    Mar 31, 2014 at 13:38

1 Answer 1


Since your server is running in the BST timezone, this is a problem related to the recent shift from GMT to BST, which occurred yesterday. At 01:00 on Sunday morning, clocks were shifted forward 1 hour (we "lost" an hour - hence Sunday was only 23 hours long) to move from GMT into BST. If you say "two days ago", this is taken into consideration and the date is correct. However if you go backwards by 172800 seconds (48 hours), then the missing hour causes you to back to 23:00 on Saturday.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .