The getdate() function returns an associative array containing date and time values for the local time, and if a timestamp is given as an argument, the date and time for that timestamp. The key or index of the associative array is a string representing the time and date value.
| Key | Value |
|---|---|
| seconds | Seconds, range 0 to 59 |
| minutes | Minutes, range 0 to 59 |
| hours | Hours, range 0 to 23 |
| mday | Day of the month, range 1 to 31 |
| wday | Day of the week, range 0 (Sunday), through 6 (Saturday) |
| mon | A month, range 1 through 12 |
| year | Year, numeric |
| yday | Day of the year, numeric |
| weekday | Day of the week, full-text format |
| month | A month, full-text format |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN">
<head>
<title>getdate()</title>
<meta Name="Author" Content="Hann So">
</head>
<body>
<p>
<?php
if (isset($_POST['submit'])) {
process_form();
}
else {
display_form();// display form for the first time
}
function display_form() {
echo <<<HTML
<h2>Get the date</h2>
<form action = "$_SERVER[SCRIPT_NAME]" method="post">
Month:
<input type="text" name="mm" size="50" value="07" />
<br />
Day:
<input type="text" name="dd" size="50" value="04" />
<br />
Year:
<input type="text" name="yy" size="50" value="1972" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
HTML;
}
function process_form() {
$mm = "$_POST[mm]";
$dd = "$_POST[dd]";
$yy = "$_POST[yy]";
$date = mktime(0, 0, 0, $mm, $dd, $yy);
$day = getdate($date);
foreach ($day as $key =>$value)
{
echo "$key => $value<br />";
}
//today
$now = getdate();
echo "<p><b>Today</b></p>";
foreach ($now as $key =>$value)
{
echo "$key => $value<br />";
}
echo "<p><a href=\"$_SERVER[SCRIPT_NAME]\">Try again?</a></p>\n";
}
?>
</p>
</body>
</html>
|