LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-29-2011, 03:09 AM   #1
iddarth.85
LQ Newbie
 
Registered: Apr 2011
Location: India
Posts: 6

Rep: Reputation: 0
Smile date format conversion


hi people,

can you please help me in conversion of the date as per the below format.

--------------------
convert "2011-03-26 15:18:39.890480" to "Feb 2, 2009 2:00:00 PM 000000"

--------------------
Thanks in dvance....
 
Old 04-29-2011, 03:21 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

Code:
date --date="2011-03-26 15:18:39.890480" '+%b %d, %Y %X %p %N'
See the date man page for all details.

Hope this helps.
 
Old 04-29-2011, 04:26 AM   #3
iddarth.85
LQ Newbie
 
Registered: Apr 2011
Location: India
Posts: 6

Original Poster
Rep: Reputation: 0
thanks druuna.... my doubt is solved....

But there is a small change to be done in your code....
Code:
date --date="2011-03-26 15:18:39.890480" '+%b %d, %Y %X %p %N'
the output for the above command is
Mar 26, 2011 03:18:39 PM PM 890480000

so removing "%p" gives the exact output
Code:
date --date="2011-03-26 15:18:39.890480" '+%b %d, %Y %X %p %N'
the output for the above command is
Mar 26, 2011 03:18:39 PM 890480000
 
Old 04-29-2011, 04:36 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

The locale setting comes into play when using %X.

You can either remove the %p (as you already discovered) or change the %X to %T and leave the %p in place. The second one is more general and does not depend on the set locale (the initial solution I posted works on my box, which probably has a different locale setting).

Hope this clears things up a bit.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Conversion : Month Name --> Number onesikgypo Programming 1 04-28-2009 12:26 PM
Date command conversion jefn Linux - Newbie 4 04-27-2009 05:43 AM
perl date conversion AndersT Programming 1 03-18-2009 05:26 PM
OpenOffice 2.0 file-format conversion nycace36 Linux - Software 5 10-18-2006 09:44 AM
List format conversion rickenbacherus Linux - General 3 10-18-2004 12:23 PM


All times are GMT -5. The time now is 05:01 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration