Browsed by
Month: September 2008

PHP: Get date for nth occurrence of weekday

PHP: Get date for nth occurrence of weekday

I looked quickly and did not see any code out there to determine the nth occurrence of a specific day of the week in a month.  For example Thanksgiving is the 4th Thursday in November.  So I designed the following

<?php
$year = 2012; 
//Pick your year
$interval = 4; 
//Week number, in this case the 4th week
$dayofweek = 4; 
//Day of week 0=Sun, 1=Mon. . .
$month = 11; 
//Month 1=Jan, 2=Feb

$firstday = jddayofweek(gregoriantojd($month, 1, $year), 0);
if($firstday <= $dayofweek){
  $date = (($interval * 7)-6) + ($dayofweek - $firstday);
}else{
  $date = (($interval * 7)-1) + (6 - $firstday);
}
echo date("n/j/Y", mktime(0, 0, 0, $month, $date, $year));
?>

It looks a little messy, but it works perfectly.

 

UPDATE:

So apparently as bad as this looks it works too:

Read More Read More

Integrating Google Talk with Roundcube

Integrating Google Talk with Roundcube

Sorry I don’t have much time at the moment to write up a whole entry about this, but I am very excited about this.

I am a big fan of roundcube but I have always wanted the ability to integrate some instant messaging into it.  Well google finally released a gtalk gadget that allows you to integrate gtalk/gchat into any page you want.  Although, google has done a very poor job of announcing this and I don’t think most people know about it.

Anyways, it is a very simple single line <iframe> code.  I just quickly added it to the roundcube template and made a few changes to the CSS code and it works perfectly.

Click the image above to see a larger screen shot.  I will write up the code for this later when I have some free time.