The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to sort a field in a file having date values risshanth Shell Programming and Scripting 4 06-04-2008 06:03 AM
Compare dates in a field and print the latest date row cvkishore Shell Programming and Scripting 1 08-04-2007 08:58 AM
Moving Part of a field to another field using AWK rjsha1 Shell Programming and Scripting 5 08-04-2006 06:39 AM
Arrange date in a field sabercats Shell Programming and Scripting 6 02-28-2006 04:56 PM
Date Handling AkumaTay UNIX for Dummies Questions & Answers 1 08-16-2001 03:53 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-03-2007
mgirinath mgirinath is offline
Registered User
  
 

Join Date: May 2005
Posts: 69
handling date field

Hi,

Is there any way we could change the date format listed below...

date I get is 03302007 (MMDDYYYY)
I need to change it to 20070330 (YYYYMMDD)

Thanks.
  #2 (permalink)  
Old 04-03-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
echo '03302007' | sed 's#\(..\)\(..\)\(....\)#\3\1\2#'

  #3 (permalink)  
Old 04-03-2007
tumblez tumblez is offline
Registered User
  
 

Join Date: Nov 2002
Posts: 15
If you are wanting the current system date in that format...

date +"%Y%M%d"

will produce...

20070903
  #4 (permalink)  
Old 04-03-2007
cfajohnson's Avatar
cfajohnson cfajohnson is online now Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,365
Quote:
Originally Posted by mgirinath
Is there any way we could change the date format listed below...

date I get is 03302007 (MMDDYYYY)
I need to change it to 20070330 (YYYYMMDD)

Separate the components, then put them back together in the order you want:


Code:
date=03302007
temp=${date#??}
month=${date%"$temp"}
day=${temp%????}
year=${temp#??}
newdate=$year$month$day

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0