Convert date stored variable into unix time BASH
NickName:user3253335 Ask DateTime:2014-01-31T18:22:10

Convert date stored variable into unix time BASH

I'm trying to convert a date stored in a variable into unix timestamp. I have the value, I must provide the format of this value("%m%d%Y") and then convert it ("%s"). Could you please give me a hint?

>initial_date=02012014
>date_2_unixtime=`date +"%m%d%Y" -d $initial_date +"%s"`
date: extra operand `+%s'
Try `date --help' for more information.

Thank you

Copyright Notice:Content Author:「user3253335」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/21477601/convert-date-stored-variable-into-unix-time-bash

Answers
anubhava 2014-01-31T10:26:45

Your date is in mmddyyyy, it needs to be in yyymmdd for date to interpret. Also you don't provide input date format to date command. Format is for display purpose only.\n\nUse it this way:\n\ninitial_date=02012014\ndt=\"${initial_date:4}${initial_date:0:4}\"\ndate +\"%s\" -d \"$dt\"\n1391230800\n",


More about “Convert date stored variable into unix time BASH” related questions

Convert date stored variable into unix time BASH

I'm trying to convert a date stored in a variable into unix timestamp. I have the value, I must provide the format of this value("%m%d%Y") and then convert it ("%s"). Could you please give me a hin...

Show Detail

Bash script to convert a date and time column to unix timestamp in .csv

I am trying to create a script to convert two columns in a .csv file which are date and time into unix timestamps. So i need to get the date and time column from each row, convert it and insert it ...

Show Detail

convert date to unix time in R

I want to convert "2013-09-16" into unix time. I found Convert UNIX epoch to Date object in R but I need to do the reverse of that. Thanks!

Show Detail

convert date to unix time in R

I want to convert "2013-09-16" into unix time. I found Convert UNIX epoch to Date object in R but I need to do the reverse of that. Thanks!

Show Detail

Convert column of Unix to date time

Trying to convert a full column of Unix into date time in R. I've been able to use as.POSIXlt(x, origin = "1970-01-01") to convert Unix. But now I'm trying to convert a whole column of Unix into ...

Show Detail

R - Convert Unix to time AND date columns

I have a dataframe which has a column (expires) with unix time codes. I want to convert these to TWO separate columns, one for time (expires_time) and one for date (expires_date). I've started with a

Show Detail

android convert unix time to utc date

I am a little confused with the unix time stamp conversion to java.util.Date involving the time zones. I have a unix time stamp that is "1367832568". it is a UTC date (Mon May 06 17:29:28 GMT+00:0...

Show Detail

Use different date as UNIX epoch time in Java?

I know that the standard UNIX epoch time is 1/1/70 and I can use this variable to convert current time to UNIX time: int time = (int) ((System.currentTimeMillis())/1000); (Note: I know it's norm...

Show Detail

Convert Unix Epoch Time to MSZ date and time

Does anyone of you have suggestions how to convert the Unix timestamp to ABAP MEZ/MESZ time and date? The following code is from the ABAP-Reference, the code is for timestamps with lenght 15 or 2...

Show Detail

Convert unix/epoch time to formatted date - unexpected date

Im trying to convert a timestamp to a human readable date and time. I tried: String dateSt = 1386580621268; Log.i("*****", "date st is = "+dateSt); long unixSeconds = Long.parseLong(dateSt); Log....

Show Detail