Jump to content

[SOLVED] Date comparision issue (First Tuesday of the Month)


drakal30

Recommended Posts

Here's a short script that gets the first Tuesday of each month of 2008. Using it as a guide, you should be able to solve your problem:

<?php
for($i=1;$i<13;$i++) {
	$st = strtotime($i . '/1/2008');
	if (date('l',$st) != 'Tuesday') // the character between the quotes in the date() function is a lowercase L
		$st = strtotime('first tuesday',$st);
	echo date('l, F j, Y',$st) . '<br>';
}
?>

 

Ken

Link to comment
Share on other sites

Hey Ken thanks for the info I came up with this on my own.  I am sure it's archaic and there is a smoother way to do it but it seems to work pretty well for me.

 

				$curYear = date('Y');
				$curMonth = date('m');
				$numDays = cal_days_in_month(CAL_GREGORIAN, $curMonth, $curYear);
				$count = 1;
				$chk = 0;

				while($count <= $numDays) {

					$chkDay = date('l',mktime('0','0','0',$curMonth,$count,$curYear));

					if($chkDay == "Tuesday") {
						$chkDate = mktime('0','0','0',$curMonth,$count,$curYear);
						$count = 50;
						$chk = 1;
					}else {
						$count++;
					}

				}



 

Basically once it hits the 1st tuesday it exits the while loop and sets a $chk var to let me know it found it and sets the date of the first tuesday in mktime format.

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.