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

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.

Archived

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

×
×
  • 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.