Problem with date command

Hello,

Can anyone have an idea what is wrong with this code:

$ YESTERDAY=$(date -d "yesterday" '+%Y-%m-%d 07:00:00')
$ echo $YESTERDAY
2016-12-26 07:00:00
$ date -d '($YESTERDAY)' +"%s000"
1482793200000

1482793200000 is not correct, it should be: 1482732000000

Result when '2016-12-26 07:00:00' is used as parameter is ok:

$ date -d '2016-12-26 07:00:00' +"%s000"
1482732000000
$ date -d '1970-01-01 1482732000 sec UTC'
Mon Dec 26 07:00:00 CET 2016

Thank you

Hello chrz,

Welcome to forums, hope you will enjoy learning/sharing knowledge here.
Could you please try following and let me know if this helps you.

date -d "$YESTERDAY" +"%s000"

Output will be as follows.

1482753600000

So if you run code date -d '($YESTERDAY)' +"%s000" or date -d 0 +"%s000" both will give same result as 1482814800000 , so you could get it as it is taking it's value as 0 for '($YESTERDAY)' .

Kindly do let me know if this helps you.

Thanks,
R. Singh

1 Like

Thank you so much, this works fine: date -d "$YESTERDAY" +"%s000"

I have never thought that I will have to ask for help on such a noble forum about date command :wink:

Regards,
chrz