seventheyejosh Posted March 4, 2009 Share Posted March 4, 2009 Hello all! I have a question that im sure has a obvious answer, but im stuck. Basically I need to populate a list of days from a span. The user will pick a start date, like Mar 3 2009. Then an end date like Mar 10 2009. Then i need a list to populate from the days between. This example would give me 3, 4, 5, 6, 7, 8, 9, and 10. Obviously. The problem im having is the month wrapping. For example, Mar 20 2009 - Apr 3 2009. How do i tell it how many days to make? Im using MySql and Php, and populating the date via a javascript picker which stores the dates in a "Mar 03 2009" esque format in fields called `start_date` and `end_date`. Thanks very much in Advance! Quote Link to comment https://forums.phpfreaks.com/topic/147841-solved-days-apart/ Share on other sites More sharing options...
ricmetal Posted March 4, 2009 Share Posted March 4, 2009 set up a few variables for the months and get an if month Mar = days 30 then from the day selected, subtract the day selected to the amount of days Mar has (info from the var = 30) then add the result to the next month, again, get the info from another variable which stores how many days the next month has and so on Quote Link to comment https://forums.phpfreaks.com/topic/147841-solved-days-apart/#findComment-775964 Share on other sites More sharing options...
samshel Posted March 4, 2009 Share Posted March 4, 2009 <?php $dtStart = "2009-03-25"; $dtEnd = "2009-04-06"; $tmStart = strtotime($dtStart); $tmEnd = strtotime($dtEnd); for($i=$tmStart;$i<=$tmEnd;$i=$i+86400) { echo date("d", $i)."<br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/147841-solved-days-apart/#findComment-775969 Share on other sites More sharing options...
seventheyejosh Posted March 4, 2009 Author Share Posted March 4, 2009 Thanks much i love it Quote Link to comment https://forums.phpfreaks.com/topic/147841-solved-days-apart/#findComment-775993 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.