LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 02: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, 02:21 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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, 03: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, 03:36 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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



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 11:26 AM
Date command conversion jefn Linux - Newbie 4 04-27-2009 04:43 AM
perl date conversion AndersT Programming 1 03-18-2009 04:26 PM
OpenOffice 2.0 file-format conversion nycace36 Linux - Software 5 10-18-2006 08:44 AM
List format conversion rickenbacherus Linux - General 3 10-18-2004 11:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration