Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date conversion

Status
Not open for further replies.

sabetik

IS-IT--Management
Nov 16, 2003
80
GU
I have the following data:
pt767350351 20050617 20050607( are dates)

is here a way to print the date as: 2005Jun17 or Jun17


Thanks
 
As far as I know, there is no 'reverse' of the date command. However you could write a simple function to perform this, based on converting the month 'number' back to its text. There are many ways of doing this. Here is the broad outline of one way to do it:
Set up a simple array called "monthtext" so that item 1 = "Jan", item 2 = "Feb", item 3 = "Mar" etc. Pass your datestring to the function, cut out characters 5 & 6, extract the text from "monthtext" and format & print the string as required.

I hope that helps.

Mike
 
Hi

I think the solution described by Mike042 should run faster, but for small amount of data this is easyer, because it not need to declare an array :

Code:
awk '{ print strftime("%Y%b%d",mktime(gensub("(....)(..)","\\1 \\2 ","") " 00 00 00")) }'

The above example transforms the [tt]$0[/tt].

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top