Jump to content

Every Friday in the month


PyraX

Recommended Posts

<?php
$month = 1; //supply month #
$year = 1998; //supply year

$date = mktime(0, 0, 0, $month, 0, $year);
$i = 1;
$days = date("t", $date);

while ($i <= $days) {
    $find_date = mktime(0, 0, 0, $month, $i, $year);
    if (date("l", $find_date) == "Friday") {
        echo "Day $i is a Friday on month #$month.<br />";
    }
    $i++;
}
?>

 

Edit: Works fine :P.

Thanks so much DJTim666

 

Here is the final code:

 

$month = $m; //supply month #
$year = $y; //supply year
$timestamp = strtotime("$m/01/$y");
$date = mktime(0, 0, 0, $month, 0, $year);
$i = 1;
$days = idate("t",$timestamp);

while ($i <= $days) {
    if (date("l",strtotime("$m/$i/$y")) == "Friday") {
        echo "Day $i is a Friday on month #$month<br>";
    }
$i++;
} 

I know it says solved, but I don't think you got the updated script. You don't need all that strtotime stuff in your re-written script. mktime returns the timestamp of the month/year/day/hour/minute/second supplied.

 

Anyways, glad I could be of help :P.

 

--

DJ

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.