Date manipulation PLEASE

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-24-2006
Des
 
Posts: n/a
Default Date manipulation PLEASE

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.

Reply With Quote
  #2 (permalink)  
Old 05-24-2006
Kimmo Laine
 
Posts: n/a
Default Re: Date manipulation PLEASE

"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)


Reply With Quote
  #3 (permalink)  
Old 05-24-2006
Des
 
Posts: n/a
Default Re: Date manipulation PLEASE

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.

Reply With Quote
  #4 (permalink)  
Old 05-24-2006
Kimmo Laine
 
Posts: n/a
Default Re: Date manipulation PLEASE

"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)


Reply With Quote
  #5 (permalink)  
Old 05-24-2006
Des
 
Posts: n/a
Default Re: Date manipulation PLEASE

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);
}

Reply With Quote
  #6 (permalink)  
Old 05-24-2006
Rik
 
Posts: n/a
Default Re: Date manipulation PLEASE

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


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:38 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0