return difference of two dates in PHP -


i need compare past/future date current date in php , present difference in "4 hours until", or "2 days 3 hours until" or "5 hours ago" format. optionally in "-4h" (which bad) or "4h" (which good) format.

so in example:

x = $expiry_date - $todays_date 

if result positive, eg. $expiry_date 4 hours in future, x = "4 hours go", or "4 hrs". if result negative, example "4 hours ago" or "-4hrs".

any other, sounding result formats fine.

any please?

refer dates diff in php

$date1 = "2013-08-11"; $date2 = "2012-07-12";  $diff = abs(strtotime($date2) - strtotime($date1));  $years = floor($diff / (365*60*60*24)); $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));  printf("%d years, %d months, %d days\n", $years, $months, $days); 

or

$date1 = new datetime("2007-03-24"); $date2 = new datetime("2009-06-26"); $interval = $date1->diff($date2); echo "difference " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days ";   //or //echo "difference " . $interval->days . " days "; 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -