mhaey Posted October 1, 2007 Share Posted October 1, 2007 hi.. im having some problem regarding strtotime and date function.. i want to find the difference between two dates using strtotime.. and then use the difference in loop to determine the dates between the two given dates... but instead of year 2007.. the output year is 2001.. how come? here's my code.. <? $startDate="01/01/2007"; $endDate="01/08/2007"; $days = (strtotime($endDate) - strtotime($startDate)) / 86400 +1; for ($wd = 0; $wd < $days; $wd++) { $weekdays = date(mktime(0, 0, 0, date($startDate) , date($startDate)+$wd, date($startDate))); echo '<br>'.date("d-m-Y",$weekdays); } ?> and here is my output... 01/01/2007 01/08/2007 01-01-2001 02-01-2001 03-01-2001 04-01-2001 05-01-2001 06-01-2001 07-01-2001 08-01-2001 help.. anyone.. Quote Link to comment https://forums.phpfreaks.com/topic/71323-solved-strtotime-problem/ Share on other sites More sharing options...
mhaey Posted October 1, 2007 Author Share Posted October 1, 2007 uhmm.. i know im a noob.. but i really need an answer why the year is 2001.. ??? it might not be the strtotime.. when i check my date("mdy",strtotime("now")); it returns the right date... what should be the problem here... ??? Quote Link to comment https://forums.phpfreaks.com/topic/71323-solved-strtotime-problem/#findComment-358851 Share on other sites More sharing options...
sKunKbad Posted October 1, 2007 Share Posted October 1, 2007 I'm playing around with it, but can't promise anything. I'll post if I figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/71323-solved-strtotime-problem/#findComment-358854 Share on other sites More sharing options...
mhaey Posted October 1, 2007 Author Share Posted October 1, 2007 I'm playing around with it, but can't promise anything. I'll post if I figure it out. thank you Quote Link to comment https://forums.phpfreaks.com/topic/71323-solved-strtotime-problem/#findComment-358856 Share on other sites More sharing options...
sKunKbad Posted October 1, 2007 Share Posted October 1, 2007 <?php $startDate="01/01/2007"; $endDate="01/08/2007"; $startD = strtotime($startDate); $endD = strtotime($endDate); $diffSeconds = $endD - $startD; $days = ($diffSeconds / 86400); for ($wd = 1; $wd < $days; $wd++) { $weekdays = ($startD + 86400*($wd)); echo date("d-m-Y",$weekdays) . "<br />"; } ?> If you want the difference to include the first day, then change the for loop to $wd = 0. Quote Link to comment https://forums.phpfreaks.com/topic/71323-solved-strtotime-problem/#findComment-358875 Share on other sites More sharing options...
mhaey Posted October 1, 2007 Author Share Posted October 1, 2007 <?php $startDate="01/01/2007"; $endDate="01/08/2007"; $startD = strtotime($startDate); $endD = strtotime($endDate); $diffSeconds = $endD - $startD; $days = ($diffSeconds / 86400); for ($wd = 1; $wd < $days; $wd++) { $weekdays = ($startD + 86400*($wd)); echo date("d-m-Y",$weekdays) . "<br />"; } ?> If you want the difference to include the first day, then change the for loop to $wd = 0. thank you so much.. ^__^ Quote Link to comment https://forums.phpfreaks.com/topic/71323-solved-strtotime-problem/#findComment-358886 Share on other sites More sharing options...
mhaey Posted October 1, 2007 Author Share Posted October 1, 2007 uhmm.. i notice that when the sdate was 01/01/2007 and edate was 01/08/2007.. the output was 01/01/2007 01/02/2007 01/03/2007 01/04/2007 01/05/2007 01/06/2007 01/07/2007 what about the enddate.. Quote Link to comment https://forums.phpfreaks.com/topic/71323-solved-strtotime-problem/#findComment-358893 Share on other sites More sharing options...
mhaey Posted October 1, 2007 Author Share Posted October 1, 2007 uhmm.. i notice that when the sdate was 01/01/2007 and edate was 01/08/2007.. the output was 01/01/2007 01/02/2007 01/03/2007 01/04/2007 01/05/2007 01/06/2007 01/07/2007 what about the enddate.. never mind.. i figure it out already.. ^___^ Quote Link to comment https://forums.phpfreaks.com/topic/71323-solved-strtotime-problem/#findComment-358894 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.