PDA

View Full Version : date measurement problem [solved]


bazz
06-02-2008, 05:36 AM
Hi,

Modifying a sub routine, to try to compare dates. converted to timestamp but division by 86400 , to get a 'daily stamp' seems to make no difference to the original timestamp.

here's the code



my $check_in_date = 2008-05-15
my $check_out_date = 2008-05-07


sub get_day_status {
my $check_in = shift;
my $check_out = shift;
my $currdate = shift;

my $check_in_timestamp = build_timestamp($check_in);
my $check_out_timestamp = build_timestamp($check_out);
my $currdate_timestamp = build_timestamp($currdate);
print qq(
cits=$check_in_timestamp <br />
cots=$check_out_timestamp <br />
cdts=$currdate_timestamp <br />
);
if($currdate_timestamp >= $check_in_timestamp && $currdate_timestamp < $check_out_timestamp)
{
# my ($before, $after) = get_date_interval($check_in,$check_out);
# if($currdate >= $before && $currdate < $after){
print qq( unavailable);
return 'unavailable';
}
else
{
print q( available);
return 'available';
}
}

# build a unix timestamp
sub build_timestamp {
$iso_date = shift;
# parse and convert date to unix time
my $timestamp = str2time($iso_date);
my $newtimestamp = ($timestamp/86400);
return $newtimestamp;
}

The $currdate is set for each day of a month in a loop.

stumped on this one. :(

bazz

bazz
06-02-2008, 05:57 AM
I decided to do with day of year instead.

got it working.

bazz

oesxyl
06-02-2008, 07:20 AM
I decided to do with day of year instead.

got it working.

bazz

strptime do the same things as str2time but return an array

my ($ss, $mm, $hh, $day, $month, $year, $zone) = strptime($iso_date);

from man page.

so if you want to extract $day, position 3, starting with 0 you can do:


my $day = (strptime($iso_date))[3];


regards