Solved

date question

Posted on 2000-03-27
2
183 Views
Last Modified: 2006-11-17

I need to write an if/else statement with the if being:

If current date is after the second sunday of march and before the second wednesday of june.......

I know how to do the basic if/else statement, but don't know how to write this 'if', could someone give me an example?

It needs to work annually, so year will not be included.

Thanks,

Chris
0
Comment
Question by:ChrisAndrews
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Expert Comment

by:mafweb
ID: 2663039
try the following: the time() function returns the seconds since 1970-01-01
then, you check the days from the eighth of march to the fourteenth of march of the year interesting you (current year?) by first calculating their time (in secs) and then using the date("l", $time) function to  see whether it a "sunday" When you've  found the sunday, store its value, so the same for the interval in june, and then do
if (time()>$start && time()>$end) ...

hope this helps
maf
0
 

Accepted Solution

by:
brad_fuller earned 100 total points
ID: 2663640
This script  uses date math functions to work out  this info

I orginally wrote it to send remnders on the second and 4th
mondays of the month - so it's a bit of a hack :^)

I tried to tidy it up for you, but I think you'll get the idea... hope the text isn't wrapped by this form ...

<?

function GetTargetDate($monthnumber,$target_day,$target_day_occurrence) {
// where:
//      $monthnumber=1 to 12 ; // march=3
//       $target_day=0-6 ; // 0=sunday, 1=monday ...
//       $target_day_occurrence - which day in the month (eg 2nd / 3rd monday )

$oneday=86400 ; //seconds
$now=time();
$thisyear=date("Y",$now);

$firstofmonth=mktime(0,0,0,$monthnumber,1,$thisyear);
$lastofmonth=mktime(0,0,0,$monthnumber+1,1,$thisyear); // first day of next month
$lastofmonth=$lastofmonth-$oneday; // the day before (I love date math :^)

$testday=$firstofmonth; // start from day one
// find first "$target_day" in this month (Sunday is daynumber 0)
do {
      $daynumber=date("w",$testday);
      $testday += $oneday; // next day
} while ($daynumber!=$target_day);

$target_date=$testday-$oneday; // doh - we just went one day over of course.

$target_date=$target_date + (($oneday * 7) * ($target_day_occurrence-1)) ;

return $target_date;

}

// examples:
$startdate=GetTargetDate(3,0,2);
print "<P> 2nd sunday in march is " . date( "d - M - Y",$startdate) ;

$finishdate=GetTargetDate(6,3,2);
print "<P> 2nd wednesday in june is " . date("d -M -Y",$finishdate) ;

$todaysdate=date("d",$now);

if (($todaysdate <= $startdate) && ($todaysdate <= $finishdate) ) {
      // do whatever.
} //endif

?>
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question