This is a discussion on Date manipulation PLEASE within the PHP Language forums, part of the PHP Programming Forums category; I have to do an events calender for a church. The events display will be limited to that week. If ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have to do an events calender for a church. The events display will
be limited to that week. If someone went in today Wed 24th I want to display 21st to 27th. I dont want any code samples, just the functions that find the day of week and a function that can (in this case) subtract 3 days to get sunday and add 7 for saterday. I can do the rest. Desmond. |
|
|||
|
"Des" <desotuatail@aol.com> wrote in message
news:1148464191.266932.319310@38g2000cwa.googlegro ups.com... >I have to do an events calender for a church. The events display will > be limited to that week. If someone went in today Wed 24th I want to > display 21st to 27th. I dont want any code samples, just the functions > that find the day of week and a function that can (in this case) > subtract 3 days to get sunday and add 7 for saterday. I can do the > rest. > I'd try something like this: $lastsunday = date('w')==0 ? mktime() : strtotime('last sunday'); // If today _is_ sunday, then today, else last sunday echo date('Y-m-d',$lastsunday); $nextsaturday = strtotime('next saturday',$dateforlastsunday); // Next saturday counting from the given sunday. echo date('Y-m-d',$lastsaturday); strtotime is a pretty darn good way for getting expressional dates like "next month" or "last year" etc. -- "ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg) |
|
|||
|
"Des" <desotuatail@aol.com> wrote in message
news:1148466523.938047.57880@j55g2000cwa.googlegro ups.com... > Well this kind of works. The code output i get is > > 2006-05-21 > 1970-01-01 > > I don't think 1970 is the next saturday. Also I need this in a format > suitable for an SQL Query. > > Des. > Sorry about that, and way to go with sarcasm by the way. (It always helps when someone is trying to _help_ you and you reply sarcastically "I don't think 1970 is next saturday"...) I first wrote the code using variable names $dateforlastsunday but then changed them to $lastsunday etc... Except in one critical place... :) Below is a working code with the typo fixed. $lastsunday = date('w')==0 ? mktime() : strtotime('last sunday'); // If today _is_ sunday, then today, else last sunday echo date('Y-m-d',$lastsunday); $nextsaturday = strtotime('next saturday',$lastsunday); // Next saturday counting from the given sunday. echo date('Y-m-d',$lastsaturday); YYYY-mm-dd is a general date format that most databases do support and since you mentiond you can do the rest, I'm sure you'll be able to make with the correct date format on your own. Just in case: http://php.net/manual/en/function.date.php -- "ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg) |
|
|||
|
Problem solved re-invent the wheel. add to functions to the include
file function Sunday() { $day = 86400; $stamp = time(); $sunday = date('w',$stamp); $stamp -= $day * $sunday; echo date('Y-m-d',$stamp); } function Saturday() { $day = 86400; $stamp = time(); $sunday = date('w',$stamp); $sunday = 6 - $sunday; $stamp += $day * $sunday; echo date('Y-m-d',$stamp); } |
|
|||
|
Des wrote:
> I have to do an events calender for a church. The events display will > be limited to that week. If someone went in today Wed 24th I want to > display 21st to 27th. I dont want any code samples, just the functions > that find the day of week and a function that can (in this case) > subtract 3 days to get sunday and add 7 for saterday. I can do the > rest. You don't want codesamples? Ok, return your day of the week with date() or strftime(), make dates with mktime(). Grtz, -- Rik Wasmus |
![]() |
| Thread Tools | |
| Display Modes | |
|
|