I have a cron which runs every minute calculates the difference between current time and an entry made. This cron will stop after business hours and run again when business hour starts.
I'm having an issue only when the entry is made on the evening (6pm) of tuesday and the difference is calculated with 1am of Wednesday.
How can I fix this?
Here is my code:
$ticket_created_timestamp = strtotime($ticket_created_time);
$current_time = date("H:i:s");
$current_timestamp = strtotime($current_time);
$time_difference_timestamp = $current_timestamp - $ticket_created_timestamp;
i don't see any particular problem here but my guess is - perhaps strtotime can't correctly interpret your ticket created time value
try something like that instead
$ticket_created_time = "2016-08-17 12:00:00";
$objDateCreatedTicketTime = DateTime::createFromFormat("Y-m-d H:i:s", $ticket_created_time);
$objDateTime = new DateTime();
$time_difference_timestamp = $objDateTime->getTimestamp() - $objDateCreatedTicketTime->getTimestamp();
The main advantage with this method is, that you've something standardized. You can decide how your date input looks like without loosing the flexibility of handling your dates correctly.