Date/Time Functions

Simple Date Display

<?php echo date("M d, Y H:i:s", time()); ?>

Basic Calendar

<?php

echo '<h5>Calendar For: '.date("F Y").'</h5>';

// get current date as array
$now = getdate(); 

// calculate the last day of this month

$end = 31;
while (!checkdate($now['mon'], $end, $now['year'])) --$end;

echo '<table border="1"><tr>
    <th><b>S</b></th>
    <th>M</th>
    <th>T</th>
    <th>W</th>
    <th>T</th>
    <th>F</th>
    <th><b>S</b></th>
</tr><tr>';

// determine day of the week for the 1st of the month
// and add the necessary padding
$now = getdate(mktime(0,0,0,$now['mon'], 1));
if ($now['wday'] > 0) { // not sunday
    echo str_repeat('<td> </td>', $now['wday']);
}

$s = 1;
while ($s < ($end + 1)) {
    $ts = getdate(mktime(0,0,0,$now['mon'], $s));
    if (!$ts['wday']) { // if Sunday start new row
        echo '</tr><tr>';
    }
    echo '<td align="right">'.$s.'</td>';
    
    $s++;
}
echo '</tr></table>';

?>

Loading ...

Related Results :

  1. Date/Time Functions
Note :
  • Related Posts are generally User Blog posts.
  • or Other tutorials from other networks of w3clan.com.
  • Any registered user can create related posts based on search term tags.

About the Author