To convert a date(in string format) to unix timestamp

Hi All,
I have a string like below.
"Mar 31 2009" .
I want to convert this to unix time .

Also please let me know how to find the unix time for the above string minus one day. For Eg. if i have string "Mar 31 2009" i want to find the unix time stamp of "Mar 30 2009".

Thanks in advance,
Giri

---------- Post updated at 05:36 AM ---------- Previous update was at 04:56 AM ----------

Can anyone please respond for this ?
Thanks,
Giri

date -d "Mar 31 2009"

Hi Siba,
I tried using the command provided by you, but error outs with the below error mesage.
date: Not a recognized flag: d
Usage: date [-u] [+"Field Descriptors"]

Kindly help .

Thanks,
Giri

Which flavour of unix you are using?

I use AIX and my shell is ksh.

If you know the date then just use..

echo "Mar 31 2009" | awk '{print $1 " " $2-1 " " $3}'

or else to print yesterday's date use...

date | awk '{print $3-1 " " $2 " " $6}'

Hi abovais,

I tried with the below command provided by you,
echo "Mar 31 2009" | awk '{print $1 " " $2-1 " " $3}'

Its gives me "Mar 30 2009" . Now i want to convert this string to unix time. Kindly help me.
Thanks in advance,
Giri.

The above solution is not feasible because if one enter the date as "Mar 1 2009" then the result would be "Mar 0 2009".

Hi Everyone,
Can any one please help me to do this. [ changing the string "Mar 30 2009" to unix time]

thanks,
Giri

Ya agreed with Siba's comments. In that case you will need to write a full fledged shell script...

Hi abovais,
Ok i will try writing a script, but i need a help, Please let me know how to convert the string below to unix time.
"Mar 30 2009"

Thanks,
Giri

Unix string? - whats the format that you want? Please, give example.