2009-12-06

date command madness

OK, is it me or am I being thick.

Linux date command takes a -d argument which is very useful as it allows a description of the time you want.

e.g. date -d "5 minutes" done at 08:23:37 today gives Sun Dec 6 08:28:38 GMT 2009
Its really useful. You can even do things like date -d "next tuesday" which says Tue Dec 8 00:00:00 GMT 2009. I use it all the time.

But...

date -d "07:48 -1 minute" gives Sun Dec 6 07:50:00 GMT 2009
date -d "07:48 -2 minute" gives Sun Dec 6 07:51:00 GMT 2009
date -d "07:48 -3 minute" gives Sun Dec 6 07:52:00 GMT 2009
date -d "07:48 -4 minute" gives Sun Dec 6 07:53:00 GMT 2009

and...

date -d "07:48 +1 minute" gives Sun Dec 6 07:48:00 GMT 2009
date -d "07:48 +2 minute" gives Sun Dec 6 07:47:00 GMT 2009
date -d "07:48 +3 minute" gives Sun Dec 6 07:46:00 GMT 2009
date -d "07:48 +4 minute" gives Sun Dec 6 07:45:00 GMT 2009

Is it just me or is that kind of backwards...

1 comment:

  1. OK, it is me going mad. Someone has identified WTF it is doing!

    The +N or +N is seen as a time zone.
    07:48 +4 means 07:49+0004 so takes 4 minutes off the time

    The "minute" is seen as "add one minute"

    To get +ve I just need N minute.
    date -d "07:48 4 minute" is 07:52

    To get -ve I just add "ago".
    date -d "07:48 4 minute ago" is 07:44

    Thanks for Simon on irc.

    ReplyDelete

Comments are moderated purely to filter out obvious spam, but it means they may not show immediately.

Is it spring yet?

This is more like it, but is only one day! Most of our import (and today it is likely all of our import) was 2am to 5am at 14.71p. Most expo...