Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Eric Linders
August 19, 2004, 2:04 am
rate this thread
How can I determine what the date was (in YYYY-MM-DD format) last
Sunday, and the Sunday before that?
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
Thank you very much for your help in figuring this out!
- Steven C. Gallafent
August 19, 2004, 4:38 am
Re: PHP Date Question: How to Determine The Date Each of the Past3 Sundays
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 ) ) ;
$last_week_epoch = $this_epoch - ?
$two_weeks_ago_epoch = $this_epoch - ?
Eric Linders wrote:
Re: PHP Date Question: How to Determine The Date Each of the Past 3 Sundays
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) ;