For example i have 2 dates 2007-06-6(This is today . I want to take it automaticly ) 2006-01-5 So result will be 1 years 5 months 1 days Problem is some months are 30 days some of them 31 days. February is 28 days for some years. So i need detailed exact time about 2 dates. Can you help me
You can check out strtotime(), works for me. echo strtotime('-1 year'); PHP: (if thats what you want)
<? function get_string_from_today( $until ) { $now = time( ); if( $now < strtotime( $until ) ) { $time = strtotime( $until ) - $now ; $years = floor( $time / 31556926 ) ; $time = $time - ( $years * 31556926 ); $months = floor( $time / 2629743.83 ) ; $time = $time - ( $months * 2629743.83 ); $days = floor( $time / 86400 ); return sprintf ( '%d years %d months and %d days', $years, $months, $days ); } } $test1 = '12th November 2011'; $test2 = '12-12-2020'; printf("%s is %s away<br />", $test1, get_string_from_today( $test1 ) ); printf("%s is %s away<br />", $test2, get_string_from_today( $test2 ) ); PHP: It's mathematically correct, and I think it should be chronologically correct aswell, maths really isn't my strong point.....