euel Posted January 4, 2012 Share Posted January 4, 2012 Hi again! I'm trying to use this code that i found somewhere in the net to display all the dates between 2 dates. It is exactly what i need but.. I understand the code and its structure (i think) but it gives me an error (maximum execution time of blah blah) which i think is because it makes an infinite loop(not sure.. ) function GetDays($sStartDate, $sEndDate) { $sStartDate = gmdate("Y-m-d", strtotime($sStartDate)); $sEndDate = gmdate("Y-m-d", strtotime($sEndDate)); $aDays[] = $sStartDate; $sCurrentDate = $sStartDate; while($sCurrentDate < $sEndDate){ $sCurrentDate = gmdate("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate))); $aDays[] = $sCurrentDate; } return $aDays; } Appreciate the help and suggestions! Gonna browse the forums for answers for the meantime... Quote Link to comment https://forums.phpfreaks.com/topic/254324-display-dates/ Share on other sites More sharing options...
requinix Posted January 4, 2012 Share Posted January 4, 2012 Don't use gmdate() - just the regular date(). gmdate() formats time according to the GMT timezone. strtotime() parses time according to the current timezone. If they aren't the same then you might end up going backwards in time... Quote Link to comment https://forums.phpfreaks.com/topic/254324-display-dates/#findComment-1304110 Share on other sites More sharing options...
euel Posted January 4, 2012 Author Share Posted January 4, 2012 Thanks requinix! i will try this tomorrow and update you if it did work. Quote Link to comment https://forums.phpfreaks.com/topic/254324-display-dates/#findComment-1304155 Share on other sites More sharing options...
euel Posted January 5, 2012 Author Share Posted January 5, 2012 it worked requinix! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/254324-display-dates/#findComment-1304387 Share on other sites More sharing options...
kamal213 Posted January 5, 2012 Share Posted January 5, 2012 Hi @euel This looks helpful as I am looking for something similar with now clue about dates. How do I test it i.e. echo out some results Thanks Quote Link to comment https://forums.phpfreaks.com/topic/254324-display-dates/#findComment-1304551 Share on other sites More sharing options...
kamal213 Posted January 6, 2012 Share Posted January 6, 2012 Ok I recon to print out the dates it might be something like this: $aDays = GetDays('01-01-2012', '06-01-2012'); echo $aDays; The problem is it just prints out the word 'array' how do it get it to print out the dates between the above dates. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/254324-display-dates/#findComment-1304787 Share on other sites More sharing options...
euel Posted January 17, 2012 Author Share Posted January 17, 2012 @kamal213 i didnt notice your replies since i marked it solved.. if you still have a problem with echoing this: echo $aDays; since its an array, you should do it like this: print_r($aDays); Quote Link to comment https://forums.phpfreaks.com/topic/254324-display-dates/#findComment-1308423 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.