Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to do date computations in a shell script using gnu date with timestamp phrases and fail to explain these differences. Can someone enlighten me? Is this a bug?

% date -u -d "now"
Fri Aug  2 15:07:16 UTC 2013

% date -u -d "1970-01-01 00:00:00 UTC  + `date +%s` seconds"
Fri Aug  2 15:07:29 UTC 2013

% date -u -d "now -6 months -1 day"
Fri Feb  1 15:07:52 UTC 2013

% date -u -d "1970-01-01 00:00:00 UTC  + `date +%s` seconds -6 months -1 day"
Tue Jan 29 15:08:03 UTC 2013

I expected the last one to mean exactly the same as the the one before since %s is defined as "seconds since 1970-01-01 00:00:00 UTC" in the manpage.

share|improve this question

Seems like it's an order of operation error. If I do this command it works fine:

$ date -u -d "$(date -u -d "1970-01-01 00:00:00 UTC  + `date +%s` seconds") \
     -6 months -1 day"

Running this gives strange results:

$ date -u -d "$(date +%s) seconds -6 months -1 day"
Sun Sep  3 07:48:54 UTC 2056

But protecting the $(date +%s) seconds with parens seems to resolve the issue:

$ date -u -d "($(date +%s) seconds) -6 months -1 day"
Fri Feb  1 15:55:12 UTC 2013
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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