my ($date, $time) = split / /, $datetime; $date = join '/', reverse split m[/], $date; $datetime = "$date $time";
Now the dates from your example data will look like 2003/09/23 14:30 and 2003/09/30 10:00 which is in correct sorting order.
For the record, though, the culprit is you're forgetting to split up your string between date and time. So the time portion ends up trailing the year when you split the date, and the date ends up in front of the hour when split the time.
If you put a few print statements in, you'll notice the problem right away:
The solution is half there in your code already. I wonder why you assign the first parameter to $date at the beginning of your function, then never use it? If you change this bit:my ($mon, $day, $year) = split(/\//, $_[0]); my ($hour, $min, $sec) = split(/:/, $_[0]); print "$mon - $day - $year\n"; print "$hour - $min - $sec\n";
to read likemy ($date) = @_; my ($time);
the rest of your code should work as is.my ($datetime) = @_; my ($date, $time) = split / /, $datetime;
Makeshifts last the longest.
In reply to Re: date time to unix
by Aristotle
in thread date time to unix
by britney
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |