View Full Version : Date to Unix time stamp format
Carlos Camacho
2007.07.31, 07:57 AM
Hello everyone,
I'm working on now moving iDevGames content from one CMS system to another. However, I need to convert all the time and date data into Unix time stamp format.
I exported the data in question into a CSV that contains four columns. Can someone convert everything for me, and post the link to download the revised version here?
The faster I can get this done, the faster iDG will be back. ;)
http://www.idevgames.com/dates.csv
Cheers,
unknown
2007.07.31, 10:14 AM
Looks like some of the data is messed up: "Day '29' out of range 1..28 at cv.pl line 13"
I don't understand American date format..
use Time::Local;
sub epochify {
my $text = shift;
my ($first,$month,$day,$year,$hour,$min,$meridian,$re st)
= $text
=~ m!(.*)(\d+)/(\d+)/(\d+) (\d+):(\d+) (AM|PM)(.*)!;
if($meridian eq "") {
$text;
}
else {
$hour += 12 if($meridian eq "PM");
my $time = timelocal(0,$min,$hour%24,$day,$month,$year);
epochify($first).$time.epochify($rest);
}
}
open(DATES, "dates.csv");
@lines = <DATES>;
close(DATES);
map {print epochify($_); print "\n";} @lines;
Bjoernke
2007.08.01, 07:11 PM
I talked with unknown, and I didn't see any problem with the line he said gave him the error. However, my code would just pass any problem and output garbage in that case (aka. no error checking).
i made two versions:
Version 1 (http://homepage.mac.com/bvg/idg/version1.csv) just translates the dates and times, but not the strange non-entries:
976834800,1179600420,"0000-00-00 00:00:00",976834800,"0000-00-00 00:00:00"
Version 2 (http://homepage.mac.com/bvg/idg/version2.csv) replaces the non-entries with zero (runrev code for that below):
976834800,1179600420,0,976834800,0
on mouseUp
put field 1 into x
repeat for each line theLine in x
repeat for each item theItem in theLine
if the number of words in theItem > 1 then
put theItem into y
convert y from english date and time to seconds
put y & comma after temp
else
if theItem = quote & "0000-00-00 00:00:00" & quote then
put 0 & comma after temp
else
put theItem & comma after temp
end if
end if
end repeat
delete char -1 of temp
put return after temp
end repeat
put char 1 to -2 of temp into field 2
end mouseUp
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.