thendal
Programmer
- Aug 23, 2000
- 284
Hi all,
I am trying to find a time difference of 12 hours. When a users enters a value place a time stamp with it. Next time when the user tries to enter a value i check whether the timestamp has exceeded the 12 hours with respect to current time.
To do this i tried something like this ..
###
## Capture current time
$time=time();
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime($time);
$year += 1900;
$month=$mon + 1;
if($month < 10)
{
$month='0'.$month; #to display 02 instead of 2
}
if($min < 10)
{
$min='0'.$min;
}
#concat all time values
$today= $year.$month.$mday.$hour.$min.$sec
$timestamp = '1111065753' # this time stamp is generated from time() function eariler when the user sets the value
##################
###
### old time
###
##################
($sec1,$min1,$hour1,$mday1,$mon1,$year1,$wday1,$yday1,$isdst1) =localtime($timestamp);
$year1 += 1900;
$month1=$mon1 + 1;
if($month1 < 10)
{
$month1='0'.$month1;
}
if($min1 < 10)
{
$min1='0'.$min1;
}
$old_time=$year1.$month1.$mday1.$hour1.$min1.$sec1;
#-------------------------------------------
To find the 12 hour difference
$diff_time=$today-$old_time;
outputs $diff_time as 11688 ..now i am don't know how to calculate how many hours is this ...
Is there any other easier to find 12 hour time difference.
Could some one shed some light , Thank you.
I am trying to find a time difference of 12 hours. When a users enters a value place a time stamp with it. Next time when the user tries to enter a value i check whether the timestamp has exceeded the 12 hours with respect to current time.
To do this i tried something like this ..
###
## Capture current time
$time=time();
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime($time);
$year += 1900;
$month=$mon + 1;
if($month < 10)
{
$month='0'.$month; #to display 02 instead of 2
}
if($min < 10)
{
$min='0'.$min;
}
#concat all time values
$today= $year.$month.$mday.$hour.$min.$sec
$timestamp = '1111065753' # this time stamp is generated from time() function eariler when the user sets the value
##################
###
### old time
###
##################
($sec1,$min1,$hour1,$mday1,$mon1,$year1,$wday1,$yday1,$isdst1) =localtime($timestamp);
$year1 += 1900;
$month1=$mon1 + 1;
if($month1 < 10)
{
$month1='0'.$month1;
}
if($min1 < 10)
{
$min1='0'.$min1;
}
$old_time=$year1.$month1.$mday1.$hour1.$min1.$sec1;
#-------------------------------------------
To find the 12 hour difference
$diff_time=$today-$old_time;
outputs $diff_time as 11688 ..now i am don't know how to calculate how many hours is this ...
Is there any other easier to find 12 hour time difference.
Could some one shed some light , Thank you.