I have two strings in datetime format ie yyyy-mm-dd hrs:mins:secs i want to calculate number of hours between the two also even a comparison if two string are equal or not would do help needed
Use strtotime() function to convert dates into unix timestamp. For example: // Convert date to timestamp $timestamp1 = strtotime('2009-03-28 12:00:00'); $timestamp2 = strtotime('2009-03-29 12:00:00'); // Get difference in seconds $difference = $timestamp2 - $timestamp1; // Get number of hours $hours = $difference / 3600; // 3600 is number of seconds in one hour echo $hours; PHP:
As steelaz said, strtotime convert datetime to timestamp , which is in seconds & can be manage easily. - ads2help
Hello, u can do like this as welll $date1 = mktime($hr,$min,$sec,$fromMonth,$fromDay,$fromYear); $date2 = mktime($Tohr,$Tomin,$Tosec,$ToMonth,$ToDay,$ToYear); $dateDiff = $date2 - $date1; $fullDays = floor($dateDiff/(60*60*24)); Regards Stylesofts Developing Team.