Page 1 of 1

Time/Date Stamp SQL Entry via PHP. Remove when Time's up!

Posted: Thu Oct 16, 2008 9:46 am
by simonmlewis
I am looking at creating a form that when submitted, posts a date and time (though time not important) stamp to the MySQL field entry.

If the Date is within the current date (ie. Closed Date set to 11/12/08 - viewing on 12/11/08 would display it, but viewing on 12/12/08 would not show it) then it would display, otherwise it would now.

I can find many auto entry scripts for adding a date, but not idea how to get PHP to see it, and say "aahh, that date has passed, I won't show it". Or "yes, that's in the future, I'll display that".

I've seen it done in ASP.net, but haven't any idea how to code that, so cannot decipher to use here.

Any help would be appreciated.

Simon

Re: Time/Date Stamp SQL Entry via PHP. Remove when Time's up!

Posted: Thu Oct 16, 2008 10:08 am
by onion2k

Code: Select all

SELECT * FROM `table` WHERE DATE(`post_date`) >= CURDATE()

Re: Time/Date Stamp SQL Entry via PHP. Remove when Time's up!

Posted: Thu Oct 16, 2008 10:12 am
by aceconcepts
First of all you'll have to create two table fields in your database

1. strDate - datatype= DATE
2. strTime = datatype= TIME

It's important that you set the correct datatypes for every field.

In order to create date and time variables you can do the following:

Code: Select all

 
$thisDate=date("Y-m-d"); //this sets $strDate to the current date formatted like: YYYY-MM-DD (this is how a MySQL database will store it)
$thisTime=date("H:i:s"); //this sets $strTime to the current time formatted like: HH:MM:SS (this is how a MySQL database will store it)
 
For further info on date and time take a look at http://uk2.php.net/date