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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I change a imported dates format?

Status
Not open for further replies.

networkwoes

Technical User
Aug 17, 2001
13
0
0
US
I have written a script that imports a flat file which contains several dates on each line. The current format is YearMonthDay or 20011231 and I need to change then to MonthDayYear or 12312001. Each date is being handled as a variable such as $Line[0]. I was thinking I could split the string into three sections each stored as a separate variable such as $Line0Year, $Line0Month, and $Line0Day, but I do not know how to divide the line in the appropriate spots since there are no separators such as spaces or commas between each section. Anyone got an idea of how to approach this?
 
There are numerous ways but you must access each subfield and then reassemble them into the format you desire. Now there may be some modules available that do this but for something yourself try this:

$newformat=substr($oldformat,4,4).substr($oldformat,0,4);

If $oldformat contained 20011231 then $newformat would be 12312001 and that might be just what you're asking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top