Page 1 of 1

HELP NEEDED - Date Manipulation

Posted: Tue Oct 05, 2004 10:43 am
by RobertGonzalez
Can someone point me in the right direction on this question? I am building a "weekly message" CMS for a church web site. Their week starts on Sunday and they want to be able to post the Pastors sermon (or notes) for this weeks service on their web site.

What I would like to do is have the page load the message that falls on last Sunday all week long (until the next Sunday, when it loads the next week's message). I would also like to title the page "Weekly Message for Mmm, dd, YYYY" where the date is the most recent Sunday. All of the data will be stored in a MySQL table (unless the printed weekly date does not need to be).

I am drawing a total blank on how to do this. All help would be most appreciated.

Posted: Tue Oct 05, 2004 10:57 am
by feyd

Code: Select all

<?php

	echo date('M d, Y H:i:s', strtotime('last sunday'));

?>

Posted: Sat Oct 09, 2004 11:33 pm
by RobertGonzalez
OK, lets take it a step further. In the CMS I want to allow the admin to select a Sunday from a select option list. The list should contain all sundays for the year. I was thinking of using a for loop with the start pointer as 'Next Sunday', but I am not sure how to set the constraint parameter to keep the date list to this year only. Any suggestions?

Posted: Sat Oct 09, 2004 11:39 pm
by feyd
why not have a loop check the "current" year against the year you are asking for timestamps for?

Posted: Sun Oct 10, 2004 12:34 am
by m3mn0n
Helpful research links: [ [google]php date manipulation[/google] ]

[SOLVED] - Date Manipulation

Posted: Tue Oct 12, 2004 3:28 pm
by RobertGonzalez
I figured out what I want to do. Sorry for not posting back sooner. This is what I was looking for:

Code: Select all

<?php
echo '<select name="date">';
for ($date = strtotime('next Sunday'); $date < mktime(0,0,0,1,1,(date('Y')+1)); $date + 604800)
{
    echo '<option value="' . $date . '">' . date('l, F jS, Y', $date) . '</option>';
}
echo '</select>';

?>
I hope this helps someone out. This returns all Sundays with a unixtimestamp less than the first Sunday of Next Year.