Reputation: 31
So I have this method,
$time2 = get_the_time( __( 'F Y h:i:s A ', 'woocommerce' ), $order->ID );
that returns a string something like this "Tuesday 21st of January 2014 05:51:00 AM"
and I have this other method that returns a timestamp "1392099616"
$time = current_time( 'timestamp' );
I'd like to get their difference in seconds.
I'm looking into strtotime, can anyone elaborate?
EDIT: Both Method returns string data types.
Thanks!
Upvotes: 0
Views: 58
Reputation: 359
You can use your get_the_time like,
$time2 = get_the_time( __( 'd-m-Y H:i:s', 'woocommerce' ), $order->ID );
then,
$time = current_time( 'timestamp' );
$time1 = date('d-m-Y H:i:s', $time);
$date1 = new DateTime($time1);
$date2 = new DateTime($time2);
$interval = $date1->diff($date2);
print_r($interval);
You'll get the difference.
Upvotes: 0
Reputation: 978
$time2 = get_the_time( __( 'h:i:s', 'woocommerce' ), $order->ID );
change time2 to this and you will get the the time value and you can compare these
$time1 = strtotime('09:00:59');
$time2 = strtotime('09:01:00');
$gap = $time2 - $time1;
echo 'Time 1: '.date('H:i:s', $time1).'<br>';
echo 'Time 2: '.date('H:i:s', $time2).'<br>';
if($gap){
echo date('H:i:s', $diff);
}else{
echo '------';
}
Upvotes: 1