#### Archived

This topic is now archived and is closed to further replies.

# How do you find dates of specific days of the week in the future?

## Recommended Posts

Hi there ...

how does one determine the following.

I need to have a message pop up every 2nd tuesday ... and I need to be able to store this in advance.

if I being with SEP09 ... how do I easily determine what # day is the 2nd tues in OCT or NOV, etc ...

I cannot just add seconds from epoch because the # of the day will change from month to month

Can anyone help?

Gordon

##### Share on other sites

Try this:

```\$month = 8;
\$year = 2008;
\$start_of_month = mktime(0,0,0,\$month,1,\$year);
if(date('N',\$start_of_month)==2){//first day of month is tuesday
\$second_tuesday = date('d-m-Y',\$start_of_month+60*60*24*7);
}else{
\$second_tuesday = date('d-m-Y',strtotime('next tuesday',\$start_of_month)+60*60*24*7);
}
echo \$second_tuesday;

```

##### Share on other sites

```<?php

\$tue = date('N',\$timestamp);
\$day = date('d',\$timestamp);

if ( \$tue == 2 && \$day > 7 ) {
// then it's sure that is the second week and day is tuesday

..more action..

}

?>
```

tell me if i'm wrong... i think it's better solution

##### Share on other sites

Best solution... double click on the clock in the lower right hand of your screen.

##### Share on other sites

Best solution... double click on the clock in the lower right hand of your screen.

Ummm, interesting solution... Maybe i'll try to solve some of my problems on your way...

##### Share on other sites

you can always enter a regular date into the strtotime function

\$whatDayWillitBNextYear = date("l", strtotime("Sep 17 2009"));

echo \$whatDayWillitBNextYear;

\$whatDayWillitBNextYear = date("l", strtotime("09/17/2030"));

echo \$whatDayWillitBNextYear;

\$whatDayWillitBNextYear = date("l", strtotime("9 17 2010"));

echo \$whatDayWillitBNextYear;

\$whatDayWillitBNextYear = date("l", strtotime("September 17th 2042"));

echo \$whatDayWillitBNextYear;

##### Share on other sites

Edit:

```<?php

\$tue = date('N',\$timestamp);
\$day = date('d',\$timestamp);

if ( \$tue == 2 && \$day >= 7 ) {
// then it's sure that is the second week and day is tuesday

..more action..

}

?>```

btw sry for new post, i saw edit icon after posting

##### Share on other sites

Here's another way:

```<?php
for (\$y=2008;\$y<2011;\$y++)
for (\$m=1;\$m<13;\$m++) {
\$sec_tues = (date('l',strtotime(\$y . '-' . \$m . '-1')) == 'Tuesday')?date ('F jS, Y',strtotime('first tuesday',strtotime(\$y . '-' . \$m . '-1'))):date ('F jS, Y',strtotime('second tuesday',strtotime(\$y . '-' . \$m . '-1')));
echo \$sec_tues.'<br>';
}
?>```

Ken

##### Share on other sites

wouldn't this work in strtotime?

strtotime("second tuesday in next month")

##### Share on other sites

No. I tried:

```<?php
cho date('F jS, Y',strtotime("second tuesday in next month"));
?>```

and got

```December 31st, 1969
```

which is what you get when strtotime() doesn't recognize the date string.

Ken

×

• #### Activity

• Chat
×
• Create New...