Getting the previous date and time
I'm currently working on a website where customers are able to cancel an order, but they can only cancel it up to 4pm 1 day before the end of the order.
I know how to get the previous day, but I can't figure out how to find out if it's 4pm or not.$prevDay = date("Y-m开发者_运维技巧-d h:m:s", strtotime('-1 day', strtotime($order->date."00:00:00")));
This gives me this output: 2011-05-08 12:05:00
$prevDay = date("Y-m-d", strtotime('-1 day')) . " 16:00:00";
$orderTime = $order->date."00:00:00";
if($orderTime < $prevDay) {
// do stuff
}
EDIT: Wait, not sure if the logic is right there, but in principle the $prevDay value should give you the date of 4PM yesterday.
$ordertime = strtotime($order->date);
$prevday = strtotime('-1 day' , $ordertime);
if (time() < $prevday && date('H') < 16) {
// it's okay to cancel
}
anything more then 12 is after noon forexample 13 14 15 till the 24. then explode the output with space character and
$time = db_value
$time = explode('',$time);
compare $time[1] > 16
i hope the above sudu code helps you
精彩评论