Bad command error for date conversion


 
Thread Tools Search this Thread
Operating Systems Solaris Bad command error for date conversion
# 1  
Old 12-24-2009
Question 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.Smilie
jyothi_wipro
# 2  
Old 12-24-2009
Try this

date -u +"Thu Dec 24 00:01:00 EST 2009"
# 3  
Old 12-24-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.... Smilie
jyothi_wipro
# 4  
Old 12-25-2009
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. Smilie
# 5  
Old 12-25-2009
if you wanted generally solution, and you are not worried about the commands involved. Then you may like this,

Code:
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
# 6  
Old 12-28-2009
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
jyothi_wipro
# 7  
Old 12-31-2009
You can convert the date into seconds and then you should be able to convert it back.

Code:
 
# 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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find command giving bad status error

In a fastload teradata utility I am trying to delete the files which are older than 30days using the find and rm command as following. find . -name 'xxx_*' -mtime +30 -exec rm -f {} \; I expect it to delete all the files older than 30 days but sometimes it gives an error : find: bad status--... (3 Replies)
Discussion started by: stelkar
3 Replies

2. UNIX for Beginners Questions & Answers

Date conversion

Hi , we have a string with yyyymmdd format . how to know which date it is ? example:20120712-->sunday 20150228-->saturday 20140431-->invalid please suggest commands which work on below os : SunOS 5.10 shell: bash shell Thanks, Srinath. (10 Replies)
Discussion started by: srinadhreddy27
10 Replies

3. AIX

Date Conversion

Hi, I would like to change the incoming date format (Jun 25 2010) to 06/25/2010. I have seen date "dconv" function but i am not sure how that works. $ echo "Jun 25 2010" | nawk ' { months=" JanFebMarAprMayJunJulAugSepOctNovDec";date=$1;month=index(months,substr($1,1,3))/3; ... (3 Replies)
Discussion started by: Prashanth B
3 Replies

4. Shell Programming and Scripting

Date conversion

Trying to convert dates using a Perl Script but it has to accept formats like 3 letter month, day and year like Nov 02 2010 or 1/4/11 or 21 Feb 2011 and have it convert to something like October 20, 2011. Any ideas? (2 Replies)
Discussion started by: reduxeffect81
2 Replies

5. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

6. Shell Programming and Scripting

Julian date to Calendar date conversion

Hi all, I require to convert julian date to normal calander date in unix for eg julian date=122 now i want corresponding calander date ---------------------------------------- gr8 if give very small command/script and please explain the steps as well(imp) Thanks ... (3 Replies)
Discussion started by: RahulJoshi
3 Replies

7. Shell Programming and Scripting

Date command output conversion

hi all, i need to measure time difference between the time a process started, to the time it ended. i am assuming the following are the steps: 1. output 'date' command at start time 2. output 'date' command at end time 3. subtract the two question is, how do i subtract the two time... (4 Replies)
Discussion started by: rathajs
4 Replies

8. Shell Programming and Scripting

Conversion of date to Julian date

Hi Gurus, Need help in Conversion of date(2007-11-30) to Julian date(YYDDD)... '+%J' 2007-11-30 to 'YYDDD' Thanks (4 Replies)
Discussion started by: SeenuGuddu
4 Replies

9. Shell Programming and Scripting

Date conversion

Hi, I have the string YYYYMMDDHHMMSS like 20090801204150 and I need to convert it using the unix command date in the format: date "Saturday, 1 August 2009 20:40:59" All in one single Unix line if this is possible. What's the correct syntax? Steve Hagi (6 Replies)
Discussion started by: hagimeno
6 Replies

10. Shell Programming and Scripting

Date conversion

Hi I want to convert MAY 05 2005 01:15:00PM date format to 2005/05/05 01:15:00PM . CAn somebody suggest me a code ,I am new to unix shell programming. Thanks Arif (21 Replies)
Discussion started by: mab_arif16
21 Replies
Login or Register to Ask a Question