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 Quote 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 Quote 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] Quote 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? Quote 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 Quote 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. Quote 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 Quote 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);?> Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.