I can't find the right syntax to convert a string date in epoch timestamp.
The script is:
date -d '2012-03-02 22:00 EDT' +%s
DATEJ=`echo -n \'2012-03-02 22:00\'`
echo $DATEJ
date -d $DATEJ EDT +%s
and the result is
[gg@raspi8 ~]$ CNVDATTS
1330740000
'2012-03-02 22:00'
date: opérande supplémentaire « EDT »
Saisissez « date --help » pour plus d'informations.
Where is the fault?
It seems that the variable DATEJ
does not give the same as the string in the 1st line. If I don't write EDT
, the error is same but mention +%s
.
echo -n
? why not justDATEJ='2012-03-02 22:00'
? Also, you need double-quotes when you use $DATEJ - e.g.date -d "$DATEJ EDT" +%s
, otherwisedate
will get three arguments$DATEJ
,EDT
, and+%s
instead of two....that's why it's complaining about the extra argument (i don't speak or read french but i can make an uneducated guess :) – cas Aug 15 '19 at 10:20