Need specific date in CCYY-MM-DD.HH.MM.SS.mmmmmm format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need specific date in CCYY-MM-DD.HH.MM.SS.mmmmmm format
# 1  
Old 06-19-2013
Need specific date in CCYY-MM-DD.HH.MM.SS.mmmmmm format

Hi All,

If i have a specific date say "20130619 01:02:02.123456" [YYYYMMDD format], what is the unix command to display in
CCYY-MM-DD.HH.MM.SS.mmmmmm format?


Thanks in Advance,
# 2  
Old 06-19-2013
Check man date
# 3  
Old 06-19-2013
What have you tried so far?


Read the manual pages for the date command and check all the options.




Robin
# 4  
Old 06-19-2013
Wrench Here you go

This does the job:
Code:
date -d '20130619 01:02:02.123456' +%C%y-%m-%d.%H.%M.%S.%N | cut -b1-26

# 5  
Old 06-19-2013
Dear gacanepa,

This doesn't work for all flavours, and we're not told what is in use, hence why HemaV needs to read the manual pages for their system. I ran it and got just the output of your text, rather than the actual date. On my system, -d needs a different format so your string "20130619 01:02:02.123456" then occupies the first 26 bytes, so the actual date wanted is removed by your cut.



Robin
# 6  
Old 06-19-2013
Dear Robin,
Good point - about the flavours.
However, if you read the original question, HemaV doesn't say he/she needs to convert the actual date, but a specific date (that is why I used the -d switch). The cut is there to trim the last 3 nano second places because HemaV wanted it to display up to microsecond precision.
BTW, I am running
Code:
Red Hat Enterprise Linux Server release 5.7 (Tikanga)

here.
As to the reading man date advice, I agree that's where one needs to start. But for a newbie (ok, we're not told that is the case, but we can assume that) a working example can make things a whole lot easier - and serve as a starting point to understand the actual man page.

---------- Post updated at 11:20 AM ---------- Previous update was at 11:17 AM ----------

HemaV,
If you need to format the current date to the format you specified in your original question (instead of a specific date), try this:
Code:
date +%C%y-%m-%d.%H.%M.%S.%N | cut -b1-26

Using that example, and reading the
Code:
man page

for
Code:
date

, you will be able to better adapt it to your needs and flavour of Unix, as rbatte1 suggested earlier.
# 7  
Old 06-20-2013
I was thinking CC format is something in Julian date format and by reading the below posts i came to know that its the 1st 2 digits of year.

Thanks,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date ‘19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

2. Shell Programming and Scripting

To find files having filename containing specific date format

Hi, I have a requirement to create a shell script(tcsh) that finds all the files in a directory having the file name containing date format "YYYYMMDDHHMM" and extract the date time part ""YYYYMMDDHHMM" for further processing. Could you please have any idea on this. trades_201604040000.out... (6 Replies)
Discussion started by: gopal.biswal
6 Replies

3. UNIX for Dummies Questions & Answers

Search specific string logfile specific date range

Hi, I have logfile like this.. === 2014-02-09 15:46:59,936 INFO RequestContext - URL: '/eyisp/sc/skins/EY/images/pickers/comboBoxPicker_Over.png', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko': Unsupported with Accept-Encoding header === 2015-02-09... (8 Replies)
Discussion started by: kishk
8 Replies

4. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

5. 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

6. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

7. Shell Programming and Scripting

Increment Date in a Specific Format

Hi, This may sound a Basic, but please help I Hava a date in the Given Format yyyy_mm_dd Start_date=2008_07_09 (This is a Fixed Date) I need to Increment this Date in a For loop until it equals Current Date For(Start_date<Current_date) xxxxxxxxxxxxxxxxxxxxxxxxxxxx... (0 Replies)
Discussion started by: dsshishya
0 Replies

8. UNIX for Dummies Questions & Answers

Changing from Excel date format to MySQL date format

I have a list of dates in the following format: mm/dd/yyyy and want to change these to the MySQL standard format: yyyy-mm-dd. The dates in the original file may or may not be zero padded, so April is sometimes "04" and other times simply "4". This is what I use to change the format: sed -i '' -e... (2 Replies)
Discussion started by: figaro
2 Replies

9. 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

10. Shell Programming and Scripting

convert mmddyy date format to ccyyddd format??

hi, for reading a cobol indexed file i need to convert "mmddyy" date format to "ccyyddd" format. i checked the datecalc and other scripts but couldnt modify them to cater to my need:(... The datecalc gives an output which i believe is the total days till that date, but i want to convert it... (2 Replies)
Discussion started by: Bhups
2 Replies
Login or Register to Ask a Question