For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > September 2006 > weekday thing









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author weekday thing
roN

2006-09-18, 6:57 pm

Hi,

I need to get back the next Wednesday in following form: "Wednesday
September 20th" and the Wednesday one w later like: ""Wednesday September
27th" and it should always recalculate on the Tuesday in advance...hm know
what I'm looking for? I've been checking date functions on php.net but just
can't figure out, how i would do this, based on the day, not the date.
I'd appreciate your help!
Thank you!

Ron


roN

2006-09-18, 6:57 pm


"roN" <test@example.com> wrote in message
news:wDFPg.555112$iF6.155578@pd7tw2no...
> Hi,
>
> I need to get back the next Wednesday in following form: "Wednesday
> September 20th" and the Wednesday one w later like: ""Wednesday
> September 27th" and it should always recalculate on the Tuesday in
> advance...hm know what I'm looking for? I've been checking date functions
> on php.net but just can't figure out, how i would do this, based on the
> day, not the date.
> I'd appreciate your help!
> Thank you!


I only got as far as:
<?php
$today = getdate();
//print_r($today);
echo $today[wday]."<br>";
echo "Today is: ".$today[wday].", ".$today[month]."
".$today[mday]."/".$today[year]."<br>"; //print today
echo "next Wednesday is:<br>";
$nWED=3-$today[wday]; // get WED after day number
echo $today[mday]+$nWED;// calculate date
?>
but what if it's next month?or what if $today[wday] is > than 3?
help me please! I'm not getting much further, Thanks!
>
> Ron
>



Norman Peelman

2006-09-18, 6:57 pm

"roN" <test@example.com> wrote in message
news:wDFPg.555112$iF6.155578@pd7tw2no...
> Hi,
>
> I need to get back the next Wednesday in following form: "Wednesday
> September 20th" and the Wednesday one w later like: ""Wednesday

September
> 27th" and it should always recalculate on the Tuesday in advance...hm know
> what I'm looking for? I've been checking date functions on php.net but

just
> can't figure out, how i would do this, based on the day, not the date.
> I'd appreciate your help!
> Thank you!
>
> Ron
>
>


Take a look at the examples found here:
http://us3.php.net/manual/en/function.strtotime.php

Norm


ZeldorBlat

2006-09-19, 7:57 am


Norman Peelman wrote:
> "roN" <test@example.com> wrote in message
> news:wDFPg.555112$iF6.155578@pd7tw2no...
> September
> just
>
> Take a look at the examples found here:
> http://us3.php.net/manual/en/function.strtotime.php
>
> Norm


Yeah, strtotime() does all sorts of nifty stuff. You can always do
something like this:

$ts = strtotime('next Wednesday');
echo date('l F jS', $ts);

Gleep

2006-09-19, 6:57 pm

On Mon, 18 Sep 2006 23:06:04 GMT, "roN" <test@example.com> wrote:

>Hi,
>
>I need to get back the next Wednesday in following form: "Wednesday
>September 20th" and the Wednesday one w later like: ""Wednesday September
>27th" and it should always recalculate on the Tuesday in advance...hm know
>what I'm looking for? I've been checking date functions on php.net but just
>can't figure out, how i would do this, based on the day, not the date.
>I'd appreciate your help!
>Thank you!
>
>Ron
>



I'm not understanding exactly what you want - but this will be a good start
In this example I run a report based on the start of every Monday. And I need to know the specific
date for Monday to run in my query.

$currentMonday = date('D');

// THE NUMBER OF DAYS DIFFERENCE since MONDAY
switch($currentMonday){
case "Mon" :
$now = date('Y-m-d');
break;
case "Tue" :
$now = date('Y-m-d', mktime(0,0,0,date('m'),date('d')-1,date('Y')));
break;
case "Wed" :
$now = date('Y-m-d', mktime(0,0,0,date('m'),date('d')-2,date('Y')));
break;
case "Thu" :
$now = date('Y-m-d', mktime(0,0,0,date('m'),date('d')-3,date('Y')));
break;
case "Fri" :
$now = date('Y-m-d', mktime(0,0,0,date('m'),date('d')-4,date('Y')));
break;
case "Sat" :
$now = date('Y-m-d', mktime(0,0,0,date('m'),date('d')-5,date('Y')));
break;
case "Sun" :
$now = date('Y-m-d', mktime(0,0,0,date('m'),date('d')-6,date('Y')));
break;
}


$now will be alway be date of 'last Monday'


once you know that can also find the date for next Monday...
$x = explode("-", $now);
$nextMonday = date('Y-m-d', mktime(0,0,0,$x[1],$x[2]+7, $x[0] ));


roN

2006-09-19, 6:57 pm


"ZeldorBlat" <zeldorblat@gmail.com> wrote in message
news:1158674242.378624.5210@d34g2000cwd.googlegroups.com...
>
> Norman Peelman wrote:
>
> Yeah, strtotime() does all sorts of nifty stuff. You can always do
> something like this:
>
> $ts = strtotime('next Wednesday');
> echo date('l F jS', $ts);
>

PERFECT! Thank you very much! The done thing is on
http://www.dvdnowkiosks.com/meetingsignup.php if anyone's interested!
Great, thank you very much! :)
Ron


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com