Date command format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date command format
# 1  
Old 11-14-2013
Date command format

Hi,

I need to convert a date format "August 12, 2013 9:40:00 PM CDT" in to DD/MM formant

For example ..I am using ...
Code:
date -d "January10, 2013 04:05:00 AM CST" +%m/%d

which gives me...
Code:
01/10

However, when i'am using it against every month it is throwing errors on some months as below....
Code:
for i in January February March April May June July August September October November December ; do date -d "$i 10, 2013 04:05:00 AM CST" +%m/%d; done
01/10
02/10
date: invalid date `March 10, 2013 04:05:00 AM CST'
date: invalid date `April 10, 2013 04:05:00 AM CST'
date: invalid date `May 10, 2013 04:05:00 AM CST'
date: invalid date `June 10, 2013 04:05:00 AM CST'
date: invalid date `July 10, 2013 04:05:00 AM CST'
date: invalid date `August 10, 2013 04:05:00 AM CST'
date: invalid date `September 10, 2013 04:05:00 AM CST'
date: invalid date `October 10, 2013 04:05:00 AM CST'
11/10
12/10

can someone please help me where i'm i going wrong here..
# 2  
Old 11-14-2013
i have no issue

Code:
$ for i in January February March April May June July August September October November December ; do date -d "$i 10, 2013 04:05:00 AM CST" +%m/%d; done
01/10
02/10
03/10
04/10
05/10
06/10
07/10
08/10
09/10
10/10
11/10
12/10

# 3  
Old 11-14-2013
Quote:
Originally Posted by Kevin Tivoli
Hi,

I need to convert a date format "August 12, 2013 9:40:00 PM CDT" in to DD/MM formant

For example ..I am using ...
Code:
date -d "January10, 2013 04:05:00 AM CST" +%m/%d

which gives me...
Code:
01/10

However, when i'am using it against every month it is throwing errors on some months as below....
Code:
for i in January February March April May June July August September October November December ; do date -d "$i 10, 2013 04:05:00 AM CST" +%m/%d; done
01/10
02/10
date: invalid date `March 10, 2013 04:05:00 AM CST'
date: invalid date `April 10, 2013 04:05:00 AM CST'
date: invalid date `May 10, 2013 04:05:00 AM CST'
date: invalid date `June 10, 2013 04:05:00 AM CST'
date: invalid date `July 10, 2013 04:05:00 AM CST'
date: invalid date `August 10, 2013 04:05:00 AM CST'
date: invalid date `September 10, 2013 04:05:00 AM CST'
date: invalid date `October 10, 2013 04:05:00 AM CST'
11/10
12/10

can someone please help me where i'm i going wrong here..
Note that in the United States in areas in the Central Time Zone, daylight savings time was in effect on all of the dates that failed.

See what happens if you change CST to CDT for those dates.

Alternatively, for the time being specified, the difference between CST and CDT doesn't matter, so you could try:
Code:
for i in January February March April May June July August September October November December
do      TZ=CST6 date -d "$i 10, 2013 04:05:00 AM CST" +%m/%d
done

# 4  
Old 11-14-2013
Thanks Don.. You are absolutely right.. it is CST vs CDT... Below is what i get when i use CDT... it is basically the opposite now...

Code:
for i in January February March April May June July August September October November December ; do date -d "$i 10, 2013 04:05:00 AM CDT" +%m/%d; done
date: invalid date `January 10, 2013 04:05:00 AM CDT'
date: invalid date `February 10, 2013 04:05:00 AM CDT'
03/10
04/10
05/10
06/10
07/10
08/10
09/10
10/10
date: invalid date `November 10, 2013 04:05:00 AM CDT'
date: invalid date `December 10, 2013 04:05:00 AM CDT'

And your alternate solution works like a charm !! :-)

Thanks a Ton
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to check date format DDMMYYYY

Record: Record1|Record2|Record3|Record4|Record5|DATE1|DATE2 Need to Check DATE1 & DATE2 is in DDMMYYYY format in a file. records which not meet the date format DDMMYYYY extract to other file. (1 Reply)
Discussion started by: vivekn
1 Replies

2. Shell Programming and Scripting

Date command comparision with a different format

I have a script called " passwd_status " which gives the passwd-s status of my servers. the script output is like below password status for A: abc ks 10/05/115 1 30 ps password status for B: abc ks 09/25/115 1 30 ps password status for C: abc ks 10/10/115 1 30 ps Now , i want to... (1 Reply)
Discussion started by: charanarjun
1 Replies

3. Shell Programming and Scripting

Need command for date format

hi all, i had a requirement in my script iam passing the parameter like (its not the system date iam passing as argument like it can be any date) 2014-08-25 but in my output file it should be 08/25/2014 please guide me thanks in advance hemanthsaikumar (3 Replies)
Discussion started by: hemanthsaikumar
3 Replies

4. UNIX for Dummies Questions & Answers

Rename all Files in a UNIX Directory from one date format to another date format

Hi Unix Gurus, I would like to rename several files in a Unix Directory . The filenames can have more than 1 underscore ( _ ) and the last underscore is always followed by a date in the format mmddyyyy. The Extension of the files can be .txt or .pdf or .xls etc and is case insensitive ie... (1 Reply)
Discussion started by: pchegoor
1 Replies

5. Shell Programming and Scripting

Display date in mm/dd/yy format in sed command

Hi All, Following is my issue. $MAIL_DOC = test.txt test.txt contains the following text . This process was executed in the %INSTANCE% instance on %RUNDATE%. I am trying to execute the following script var=`echo $ORACLE_SID | tr ` NOW=$(date +"%D") sed -e... (3 Replies)
Discussion started by: megha2525
3 Replies

6. Shell Programming and Scripting

Command for changing date format in a file

Hi... I have an inputfile name as :- abc_test_20120213.dat (date in yyyymmdd format) I need the output file name as abc_test_13022012.dat (date in ddmmyyyy format) Please help me on this... Thanks in advance. (5 Replies)
Discussion started by: gani_85
5 Replies

7. Shell Programming and Scripting

How to change date format in 'last' command?

hi.. i am new to here. can anybody tell me how can we change the date format in the 'last' command. EX- on running last command i am getting -- rruat pts/12 172.18.40.101 Tue May 3 12:59 still logged in rruat pts/10 blr2-3f-239.asco Tue May 3 12:59 - 13:09 ... (2 Replies)
Discussion started by: thearpit
2 Replies

8. HP-UX

Date format of ll command

Hi, Unix: HP-UNIX. I have a requirement(part of my requirement) to get latest file modification date of all files(In a particular directory). Using ll comand i m able to find out the modification date but not in the required format My command and out put: echo trp_pb.sql `ll... (2 Replies)
Discussion started by: satyadash
2 Replies

9. Shell Programming and Scripting

Which is the STRING format in the date command?

Hi According with the 'date' command documentation My question is, which are the possible values for STRING? I have been looking in the man pages but I didn't find anything? After some googling I have found it can have special values as 'now', 'yesterday' or 'tomorrow'. If it represents... (1 Reply)
Discussion started by: islegmar
1 Replies

10. Shell Programming and Scripting

convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies
Login or Register to Ask a Question