Jump to content

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


Gordon Werner

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?

 

Thanks in advance

 

Gordon

Link to comment
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;


Link to comment
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;

Link to comment
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.