jeeva Posted January 20, 2007 Share Posted January 20, 2007 Hi,i want find the [b]number of days[/b] between the dates "2045-12-31 and 2047-12-31".i have tried with so many date functions. but i am not able to find the solution.suggestions please................jeeva Link to comment https://forums.phpfreaks.com/topic/34974-how-to-handle-the-dates-greater-than-2057-12-31/ Share on other sites More sharing options...
Hypnos Posted January 20, 2007 Share Posted January 20, 2007 The built in PHP date functions won't go past 2038.http://phplens.com/phpeverywhere/adodb_date_library Link to comment https://forums.phpfreaks.com/topic/34974-how-to-handle-the-dates-greater-than-2057-12-31/#findComment-165047 Share on other sites More sharing options...
sasa Posted January 20, 2007 Share Posted January 20, 2007 try[code]<?phpfunction in_day($a){ $monts=array(0,31,28,31,30,31,30,31,31,30,31,30,31); $a = explode('-',$a); if (($a[0] % 400 == 0) or ($a[0] % 4 == 0 and $a[0] % 100 != 0)) $monts[2] = 29; $y = $a[0] -1; $out = $y *365 + (int) ($y / 4) - (int) ($y / 100) + (int) ($y / 400); for ($i=0;$i<$a[1];$i++) $out += $monts[$i]; $out += $a[2] - 1; return $out;}$date1='2045-12-31';$date2='2047-12-31';echo in_day($date2) - in_day($date1);?>[/code] Link to comment https://forums.phpfreaks.com/topic/34974-how-to-handle-the-dates-greater-than-2057-12-31/#findComment-165091 Share on other sites More sharing options...
Jessica Posted January 20, 2007 Share Posted January 20, 2007 sasa: Does that check for leap years? Link to comment https://forums.phpfreaks.com/topic/34974-how-to-handle-the-dates-greater-than-2057-12-31/#findComment-165133 Share on other sites More sharing options...
kenrbnsn Posted January 21, 2007 Share Posted January 21, 2007 Yes it does, in this line:[code]<?phpif (($a[0] % 400 == 0) or ($a[0] % 4 == 0 and $a[0] % 100 != 0)) $monts[2] = 29;?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/34974-how-to-handle-the-dates-greater-than-2057-12-31/#findComment-165303 Share on other sites More sharing options...
Ninjakreborn Posted January 21, 2007 Share Posted January 21, 2007 Nice function. Link to comment https://forums.phpfreaks.com/topic/34974-how-to-handle-the-dates-greater-than-2057-12-31/#findComment-165310 Share on other sites More sharing options...
Jessica Posted January 21, 2007 Share Posted January 21, 2007 I wasn't sure if that's what that was - I missed the 29 part, that makes it obvious ;) thanks Ken Link to comment https://forums.phpfreaks.com/topic/34974-how-to-handle-the-dates-greater-than-2057-12-31/#findComment-165327 Share on other sites More sharing options...
subbukumararaja Posted January 22, 2007 Share Posted January 22, 2007 Hi jeeva try this one,it will help u<?phpfunction in_day($a){ $monts=array(0,31,28,31,30,31,30,31,31,30,31,30,31); $a = explode('-',$a); if (($a[0] % 400 == 0) or ($a[0] % 4 == 0 and $a[0] % 100 != 0)) $monts[2] = 29; $y = $a[0] -1; $noOfDays = $y *365 + (int) ($y / 4) - (int) ($y / 100) + (int) ($y / 400); for ($i=0;$i<$a[1];$i++) $noOfDays += $monts[$i]; $noOfDays += $a[2] - 1; return $noOfDays;}$date1='2045-12-31';$date2='2047-12-31';echo in_day($date2) - in_day($date1);?> Link to comment https://forums.phpfreaks.com/topic/34974-how-to-handle-the-dates-greater-than-2057-12-31/#findComment-166239 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.