Jump to content

Unix timestamp comparison


mflevie44

Recommended Posts

Can any one tell me what's wrong with this code? it's just keep giving me this  message  "Pick up Date atleast 24hrs after the current Date";

 

 

$pDate = $_GET['txtPDate'];

$pTime = $_GET['txtPTime'];

 

$dateArray = explode('-',$pDate);

 

$timeArray = explode('.',$pTime);

 

$hours = (int)$timeArray[0];

$minutes = (int)$timeArray[1];

 

 

$day = (int)$dateArray[0];

$month = (int)$dateArray[1];

$year = (int)$dateArray[2];

 

$userPTimes = mktime(date($hours),date($minutes),0,date($month), date($day), date($year));

 

$userCurrentTime = mktime(0, 0, 0, date($day), date($month), date($year));

$userupperlimit = mktime(date(7), date(30), date(0), date($day), date($month), date($year));

$userlowerlimit = mktime(date(20), date(30), date(0), date($day), date($month), date($year));

 

$dayafter =  mktime(0, 0, 0, date($day +1), date($month), date($year)); // I wanted $dayafter to 24 hours after the $pdate

 

if($userCurrentTime < $dayafter)

{

echo "Pick up Date atleast 24hrs after the current Date";

}

 

else if(!($userPTimes >= $userupperlimit) || !($userPTimes <= $userlowerlimit ))

{

echo "Pick up Time should be between 7.30 - 20.30";

}

Link to comment
https://forums.phpfreaks.com/topic/282521-unix-timestamp-comparison/
Share on other sites

The date() function returns a formatted date string from a unix timestamp.

 

mktime() requires six integers in the order (hr, min, sec, month, day, year)

 

 

if $ptime is a unix timestamp, the next day can be found with

$next = strtotime('+1 days', $ptime);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.