PHP Date Question: How to Determine The Date Each of the Past 3 Sundays

This is a discussion on PHP Date Question: How to Determine The Date Each of the Past 3 Sundays within the PHP Language forums, part of the PHP Programming Forums category; Hello, How can I determine what the date was (in YYYY-MM-DD format) last Sunday, and the Sunday before ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-19-2004
Eric Linders
 
Posts: n/a
Default PHP Date Question: How to Determine The Date Each of the Past 3 Sundays

Hello,

How can I determine what the date was (in YYYY-MM-DD format) last
Sunday, and the Sunday before that?

For example:

Today is Thursday, August 18, 2004 (2004-08-18). I would like to have
the following variables:

$this_past_sunday = 2004-08-14
$two_sundays_ago = 2004-08-07
$three_sundays_ago = 2004-07-31

etc. etc.

Thank you very much for your help in figuring this out!

- Eric
Reply With Quote
  #2 (permalink)  
Old 08-19-2004
Data Goob
 
Posts: n/a
Default Re: PHP Date Question: How to Determine The Date Each of the Past3 Sundays

Eric,

Clues for you, the rest is up to you to figure out.

This example would determine two dates based on epochs:

$month, $day, $year are up to you.

$this_epoch = date( "U", mktime ( 0,0,0, $month, $day, $year ) );
$next_epoch = $this_epoch + 604800 ;
$next_ts = date( "Y-m-d H:i:s", date ( $next_epoch ) ) ;

Solve:

$last_week_epoch = $this_epoch - ?
$two_weeks_ago_epoch = $this_epoch - ?

Have fun!

-DG-


Eric Linders wrote:
> Hello,
>
> How can I determine what the date was (in YYYY-MM-DD format) last
> Sunday, and the Sunday before that?
>
> For example:
>
> Today is Thursday, August 18, 2004 (2004-08-18). I would like to have
> the following variables:
>
> $this_past_sunday = 2004-08-14
> $two_sundays_ago = 2004-08-07
> $three_sundays_ago = 2004-07-31
>
> etc. etc.
>
> Thank you very much for your help in figuring this out!
>
> - Eric


Reply With Quote
  #3 (permalink)  
Old 08-19-2004
Steven C. Gallafent
 
Posts: n/a
Default Re: PHP Date Question: How to Determine The Date Each of the Past 3 Sundays

"Eric Linders" <elinders88@hotmail.com> wrote in message
news:491326e5.0408182004.52f3adf1@posting.google.c om...
> How can I determine what the date was (in YYYY-MM-DD format) last
> Sunday, and the Sunday before that?


See my reply to your other post and you should be able to get it from there.

Steve
--
Steven C. Gallafent - The Computer Guy, Inc.
steve@compguy.com - http://www.compguy.com/


Reply With Quote
  #4 (permalink)  
Old 08-19-2004
Rob Allen
 
Posts: n/a
Default Re: PHP Date Question: How to Determine The Date Each of the Past 3 Sundays

In message <491326e5.0408182004.52f3adf1@posting.google.com >, Eric
Linders <elinders88@hotmail.com> writes
>Hello,
>
>How can I determine what the date was (in YYYY-MM-DD format) last
>Sunday, and the Sunday before that?
>
>For example:
>
>Today is Thursday, August 18, 2004 (2004-08-18). I would like to have
>the following variables:
>
>$this_past_sunday = 2004-08-14
>$two_sundays_ago = 2004-08-07
>$three_sundays_ago = 2004-07-31
>
>etc. etc.
>
>Thank you very much for your help in figuring this out!
>
>- Eric



I would do something like

$7daysInSeconds = 86400 * 7;
$lastSunday = strtotime("last sunday");
$two_sundays_ago = $lastSunday - $7daysInSeconds;
$three_sundays_ago = $two_sundays_ago - $7daysInSeconds;

then format however you like. e.g.
$lastSundayString = date('Y-m-d', $lastSunday) ;
etc...

--
Rob...
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB 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 08:57 AM.


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