drakal30 Posted December 5, 2007 Share Posted December 5, 2007 I want the script to check first if the current Day is Tuesday and if the Tuesday is the first Tuesday of the current month. Thank you for all your help. Link to comment https://forums.phpfreaks.com/topic/80353-solved-date-comparision-issue-first-tuesday-of-the-month/ Share on other sites More sharing options...
kenrbnsn Posted December 6, 2007 Share Posted December 6, 2007 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 https://forums.phpfreaks.com/topic/80353-solved-date-comparision-issue-first-tuesday-of-the-month/#findComment-407396 Share on other sites More sharing options...
drakal30 Posted December 6, 2007 Author Share Posted December 6, 2007 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 https://forums.phpfreaks.com/topic/80353-solved-date-comparision-issue-first-tuesday-of-the-month/#findComment-407553 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.