<?php
include("format_timestamp_class.php");
error_reporting(E_ALL);
$my_time = new format_timestamp;
if (isset($_POST['sub_date'])) {
$my_time->reg_date = $_POST['date'];
$my_time->reg_time = $_POST['time'];
// this property will output an other seperator then a minus
$my_time->date_seperator = ".";
// use this property if you have a not english styled date
$my_time->date_format = (isset($_POST['date_type'])) ? $_POST['date_type'] : "us";
// next convert the date
$my_time->conv_date_format();
// the next method will create the mysql timestamp
if ($my_time->create_mysql_timestamp()) {
$mysql = $my_time->mysql_timestamp;
// after this you can convert this to an unix stamp
$unix = $my_time->conv_to_unix_timestamp();
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example format timestamp class</title>
<style type="text/css">
<!--
label {
width: 100px;
}
input {
margin-bottom:3px;
}
form {
margin-left:50px;
}
#main {
width:480px;
margin:0 auto;
text-align:left;
}
-->
</style>
</head>
<body style="text-align:center;">
<div id="main">
<h2>Example date/time to MySQL and UNIX timestamp conversion</h2>
<p>Some people have problems with the conversion from a date posted by a form and into a format for later calculations or just putting the value into a database.<br>
With this class is it possible to convert a date and time field into a (MySQL or UNIX) timestamp. Of course you can extract date and time from a timestamp, too. Before conversting there is a test to check that a date/time is valid.</p>
<p>Try it, insert a date and time and notice both timestamps.<br>The format for a non english date is: <b>dd-mm-yyyy</b></p>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<label for="date">Date:</label>
<input type="text" name="date" value="<?php echo (isset($_POST['date'])) ? $_POST['date'] : "yyyy-mm-dd"; ?>" size="15"><br>
<label for="time">Time:</label>
<input type="text" name="time" value="<?php echo (isset($_POST['time'])) ? $_POST['time'] : "hh:mm:ss"; ?>" size="15"><br>
non english date?*
<input type="checkbox" name="date_type" value="eu"<?php echo (isset($_POST['date_type'])) ? " checked" : ""; ?>><br>
<input type="submit" name="sub_date" value="Convert!">
</form>
<p><b><?php echo (isset($my_time->error)) ? $my_time->error : " "; ?></b></p>
<?php if (isset($mysql) && isset($unix)) { ?>
<p>Your date time as MySQL timestamp: <b><?php echo $mysql; ?></b><br>and as UNIX timestamp: <b><?php echo $unix; ?></b></p>
<p>Notice the extracted date with different seperators: <b><?php echo $my_time->extract_date(); ?></b></p>
<?php } ?>
</div>
</body>
</html>
|