datetime - Create a bash date/time variable from argument -


given argument being passed in this:

~/documents/checkout/check-out.sh potatoes '2013/05/22 13:43:00' 

using 1st or 2nd line, produces

st=`date --date "$2" +%s`                   # mogul's suggestion st=$(date --date="$2" +%s)                  # kent's suggestion st=$(date --date="2013/05/22 14:45:00" +%s)  date: illegal option -- - usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdhms]] ...      [-f fmt date | [[[mm]dd]hh]mm[[cc]yy][.ss]] [+format] 

os x's version of date doesn't understand --date option; need use -f , give format of input date:

st=$(date -j -f "%y/%m/%d %t" "$2" +%s) 

for example:

$ date -j -f "%y/%m/%d %t" "2013/05/22 14:45:00" +%s 1369259100 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -