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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

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

Post by onion2k »

Code: Select all

SELECT * FROM `table` WHERE DATE(`post_date`) >= CURDATE()
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

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

Post 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
Post Reply