Jump to content

[SOLVED] Comparing Dates with strtotime() -- What the heck?


Recommended Posts

As usual, my lizard brain encounters significant obstacles when dealing with the intricacies of php, but in this case, I feel vindicated, as I'm finding the same problem throughout my searches, so it's not just me...

 

I'm building a schedule script--well, modifying one I built last year--to add an event every second and third Sunday of the month.  However, when I try to find that Sunday, and compare to my timestamp, I run into trouble:

$myDays = getMyDays(); 

$keys = array_keys( $myDays['raw'] );
$keys = count($keys);  

for($s = 0; $s < $keys; $s++) 
{ 
$schedday = date('l, F jS Y', $myDays['raw'][$s]); 

$frdays = date('l, F jS Y', strtotime("fifth sunday" ,$myDays['raw'][$s]) ); 
  
echo $frdays . $schedday;
       
        if ($schedday = $frdays)
          {echo 'everybody hold hands.';}
         }

This seems to stem from the fact that strtotime() doesn't count the first occurence of the date...at least not the way I'm trying to find it.

I've tried creating a new variable, and using that as my second strtotime parameter, but I get this error:

strtotime() expects parameter 2 to be long, string given

 

So, I'm baffled.

 

I need to compare the Sunday in my array to the actual third Sunday of the month, right?  But, I'm just not getting it...

 

Any and all help is most humbly appreciated.

 

 

 

 

hmm...What I did was set up an if-else statement, that would change the day I was looking at, depending on the first day of the month.

 

This may have been the long way to go about it--but at least I solved it!!!

 

if ( date('w', strtotime("first day",$ts)) == 0) //$ts is my desired timestamp.  I'm essentially saying if the first day of the month is a Sunday, then don't count it.
	{
	$frday10 = date('l, F jS Y', strtotime("third sunday" ,$ts) );   
	$frday50 = date('l, F jS Y', strtotime("fourth sunday" ,$ts) );   
	}
else
	{
	$frday10 = date('l, F jS Y', strtotime("second sunday" ,$ts) );  
	$frday50 = date('l, F jS Y', strtotime("third sunday" ,$ts) );
	}

 

I can now use this on both a projected schedule and a current month's schedule, depending on how I want to use it.

 

It may be rough and basic, but it works!

 

 

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.