//get current month
$currentMonth=date(“m”);
//work out the season
if ($currentMonth>=”03″ && $currentMonth<=”05″)
$season = “spring”;
elseif ($currentMonth>=”06″ && $currentMonth<=”08″)
$season = “summer”;
elseif ($currentMonth>=”09″ && $currentMonth<=”11″)
$season = “autumn”;
else
$season = “winter”;
This example converts 24 hour formatted date to 12 hour formatted dates
<?php
function Convert24to12($time)
{
return date(‘g:i:sa’, strtotime($time));
}
/*some examples follow*/
echo Convert24to12(‘12:12:12′).’<br />’;
echo Convert24to12(‘12:12′).’<br />’;
echo Convert24to12(‘08:12:12′).’<br />’;
echo Convert24to12(‘08:12′).’<br />’;
?>
This is a clock that updates, it actually merely does a refresh every 1 second, this is assuming that you create a file called clock.php and copy the examnple below into it
<HTML>
<HEAD>
<TITLE></TITLE>
<META HTTP-EQUIV=”refresh” CONTENT=1″; URL=clock.php”>
</HEAD>
<BODY>
<?php
Print “The time is: “;
$hour = date(‘H’); //hours.
$minute = date(‘i’); //minutes.
$seconds = date(’s’); //seconds
$time = “$hour : $minute : $seconds”; //put [...]
Create a date and time using the mktime function
<?php
$timestamp = mktime(11, 15, 0, 7, 23, 2009);
print date(“m/d/y G.i:s<br>”, $timestamp);
print “<br>”;
print “The date is “;
print date(“j of F Y, \a\\t g.i a”, $timestamp);
?>
Check if a date is in a valid format
<?php
if (checkdate(11, 12, asa))
//if (checkdate(11, 12, two and six))
{
echo “Date is in a valid format”;
}
else
{
echo “Date is not valid”;
}
?>