Jump to content

date_diff($date1,$date2) function is not giving me correct result


php_developer
 Share

Recommended Posts

Hello, I am working with date_diff($date1,$date2) function but it is not giving me correct result... I have copied and pasted the following code:<?php$date1=date_create("2013-03-15");$date2=date_create("2013-12-12");$diff=date_diff($date1,$date2);echo $diff->format("%R%a days");?>from : http://www.w3schools.com/php/showphp.asp?filename=demo_func_date_diff but it is not giving me the same result ("+272 days") as the above refference says(shows), rather it gives me "+6015 days", which is wrong. Please let me know, am i going wrong... or is there any other problem

Link to comment
Share on other sites

But I am not getting the correct result. Not even for the following code:<?php$datetime1 = date_create('2009-10-11');$datetime2 = date_create('2009-10-13');$interval = date_diff($datetime1, $datetime2);echo $interval->format('%R%a days');?> Do I need to change some date setting at my desktop or is there any php version issue...? Please let me know..

Link to comment
Share on other sites

Its 5.3.5(xampp)..I realy don't know why is this function not giving me correct result at my localhost.What ever date I am putting in this function, it gives me same result as, "+6015 days". But will it work correctly online (at server, there may be an issue at my localhost)...?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...