PDA

View Full Version : Php date and time function



stedem
April 16th, 2009, 04:25 AM
Hello,

I'm busy with my new website and want to do some things with "date".

I would like to create a function in my site that shows/hides a product based on date.

For example in the field "show" i put the date 2009-04-19 and from that date the product will be shown. If i put in the "hide" field the value 2009-04-21 the product must be hidden from the 21st.

Is this possible in a easy way?

Greetz

NeoDreamer
April 16th, 2009, 05:53 PM
I suppose you have your products stored in a MySQL database and you have a $database class written:



<?php

$secondsInDay = 86400;
$date = $_POST['showDate'];
$timeStamp = strtotime($date);

$query = 'SELECT *
FROM products
WHERE date BETWEEN ' . $timeStamp . ' AND ' . ($timeStamp + $secondsInDay);

$query = $database->query($query);

while($row = mysql_fetch_array($query))
echo $row['productName'] . '<br />';

?>