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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
"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/ |
|
|||
|
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... |