If you need to search for specific dates or date ranges, the database engine is better equipped than bare Perl.
SELECT
your_fields
FROM
your_table
WHERE
Timestamp_field BETWEEN "2003-02-01 10:30"
AND "2003-02-05 12:00"
Moreover, MySQL has
a large collection of date-oriented functions, which you should consider before burdening your client with tasks that should belong in the server.
However, if you really must, you can extract from a timestamp value the same fields that you get from localtime.
#!/usr/bin/perl -w
use strict;
my ($sec,$min,$hour,$mday,$mon,$year) =
localtime(1044436437); # Wed Feb 5 10:13:57 2003
$year += 1900;
$mon++;
my $timestamp = "20030205101357";
my ($tyear, $tmon, $tmday, $thour,$tmin, $tsec) =
$timestamp =~ /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/;
printf " Time Timestamp\n";
printf "year %4d %4d\n", $year, $tyear;
printf "month %4d %4d\n", $mon, $tmon;
printf "day %4d %4d\n", $mday, $tmday;
printf "hour %4d %4d\n", $hour, $thour;
printf "min %4d %4d\n", $min, $tmin;
printf "sec %4d %4d\n", $sec, $tsec;
Having done that, you can easily compare fields coming from localtime with the ones coming from timestamps.
For complicated operations, you may want to trust some modules, such as
Date::Calc or Date::Manip
_ _ _ _
(_|| | |(_|><
_|
|