Forum Moderators: coopster

Message Too Old, No Replies

How to get Future Dates

         

ferhanz

8:21 pm on Nov 16, 2005 (gmt 0)

10+ Year Member



I am looking for a query in which i can get all the future dates for let say Monday 11:00 am

e.g 21 - Nov - 2005, 28 - Nov - 2005 and so on

wsmeyer

8:35 pm on Nov 16, 2005 (gmt 0)

10+ Year Member



Would just setting the start date as the first Monday and then looping through x number of times adding 7 days each time work?

William.

mooger35

9:35 pm on Nov 16, 2005 (gmt 0)

10+ Year Member



Why not just use WHERE in your query?

$today = date("Y-m-d");
$query_schedule = "SELECT DATE_FORMAT(date '%a, %b %e') AS date2, etc etc etc
FROM schedule
WHERE DATE_FORMAT(date, '%a') = 'Mon' AND date > $today
ORDER BY date ASC";

ferhanz

9:51 pm on Nov 20, 2005 (gmt 0)

10+ Year Member



Well i am using the following code to get the future Monday dates ..the only thing left in it is that it gets the current date and add 7 days in it so it can only work if the day is monday, what i need is that somehow it should get the comming monday automatically and put it in the first_monday

$first_monday = date(); //set the date of the first monday (this will be week1)
$first_monday_timestamp = strtotime($first_monday); //convert to Unix timestamp
$weeks = 5; //number of weeks
$week_in_seconds = 60*60*24*7; //number of seconds per week (7 days)

for ($i = 0; $i < $weeks; $i++)
{
$date_timestamp = $first_monday_timestamp + ($week_in_seconds * $i);
$date = date("l Y-m-d", $date_timestamp);
$week_number = $i + 1;
echo "Week" . $week_number . ": " . $date;
echo "<br>";
}

sunveria

10:40 am on Nov 22, 2005 (gmt 0)

10+ Year Member



Hope this help..

$weekdays=date("w");
$weeks = 5; //number of weeks
$week_in_seconds = 60*60*24*7; //number of seconds per week (7 days)
$interval_day_from_monday=$weekdays-1;
$first_monday_timestamp=mktime(0,0,0,date("m"),date("d")-$interval_day_from_monday,date("Y"));
for ($i = 0; $i < $weeks; $i++)
{
$date_timestamp = $first_monday_timestamp + ($week_in_seconds * $i);
$date = date("l Y-m-d", $date_timestamp);
$week_number = $i + 1;
echo "Week" . $week_number . ": " . $date;
echo "<br>";
}

^ ^