Use Time::Local for the function timelocal, which is the inverse of the builtin localtime.
For example:
use strict; use warnings; use Time::Local; my $date = "06/06/2009"; my ($m,$d,$y) = $date =~ m|(\d+)/(\d+)/(\d+)|; my $timet = timelocal(0, 0, 0, $d, $m-1, $y); print "Date '$date' => $timet\n" # Updated -- check the reverse my $ltime = localtime($timet); print "$timet => $ltime\n"; # Results: # Date '06/06/2009' => 1244260800 # 1244260800 => Sat Jun 6 00:00:00 2009
Note that the first three arguments to timelocal above represent (respectively) the number of seconds, minutes, and hours; in your case they can be zero, as you're only interested in a one-day granularity.
Update: As Corion reminds me, the month passed to timelocal needs to be zero-based, not one-based the way humans represent dates. Changing "$m" to "$m-1" in my code fixed this (thanks, Corion!).
In reply to Re: String (date) to time (integer)
by liverpole
in thread String (date) to time (integer)
by northwestdev
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |