Reputation: 2004
Hello i am writing a module in PHP. Here I have to check for the condition like if user select demo for application with basic features he should get demo for next day till 12 PM. I am using code
date_default_timezone_set("Asia/Kolkata");
echo date("Y-m-d 12:00:00",strtotime('tomorrow'))
it is working fine. But when user try for demo account in mid night that is same date as next day. it is giving me the day after tomorrow date. For example today is 22/01/2014 before 22/01/2014 11:59PM it is working fine. but 23/01/2014 00:01 AM it is giving date 24/01/2014 12:01PM but i want it to be 23/01/2014 12:01PM. Any suggestion.
Upvotes: 0
Views: 868
Reputation: 11972
date_default_timezone_set("Asia/Kolkata");
$day = date('H') < 12 ? 'today' : 'tomorrow';
echo date("Y-m-d 12:00:00",strtotime($day));
The key is to work out which day the demo should end, this can be done by checking the current hour. If the current hour is less than 12, then it should be today's date, otherwise tomorrow's.
Upvotes: 1