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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -