Bad command error for date conversion

Hi,

Iam trying to convert date and time to milliseconds which iam using in a script on Sun Solaris.
I have searched the posts on the forum but i could not get any solution.

The format iam using in script is:

date -u "Thu Dec 24 00:01:00 EST 2009"

But i get a bad command error.

Can someone help me out.:o

Try this

date -u +"Thu Dec 24 00:01:00 EST 2009"

Its printing me the same format iam sending in that ie
date -u +"Thu Dec 24 00:01:00 EST 2009"

result is Thu Dec 24 00:01:00 EST 2009.

But i want that to convert it into milliseconds ie i want the output as 1261593060000.
Someone help me out.... :frowning:

If you are looking for converting the provided date to the format you can use the format controls.
try this

# date --date="Thu Dec 24 00:01:00 EST 2009" "+%m%d%y%H%M%S"

output: 122409103100

Hope this helps. :slight_smile:

if you wanted generally solution, and you are not worried about the commands involved. Then you may like this,

22:12:22 : tmp :cat t.pl 
use DateTime;
$dt = DateTime->new( year   => 1974, month  => 11, day    => 30, hour   => 13, minute => 30, 
    second => 0, nanosecond => 500000000, time_zone => 'Asia/Taipei' );
$epoch_time  = $dt->epoch;
print "$epoch_time\n";
22:12:25 : tmp :perl t.pl
155021400

From here: Perl Epoch Converter Routines

Hi All,

For my above query,iam running my script in the below way:
date Mon Dec 28 10:31:33 IST 2009
Date_val=`date "+%m%d%y%H%M%S"`
echo $Date_val

And i get the output as 122809164608
But when i convert 122809164608 back to day month year format it gives me the output for 1973 ie as below
Thu Nov 22 15:08:25 IST 1973

But I want for the date i provide.
Can someone tell where am I goin wrong?

Regards,
Jyothi

You can convert the date into seconds and then you should be able to convert it back.

 
# date --date="Thu Dec 24 00:01:00 EST 2009" +%s
1261630860
# date --date="1970-01-01 1261630860 sec" +"%a %b %d %T %Z %Y"
Thu Dec 24 05:01:00 CST 2009
 

Hope this helps