Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

manipulating date for insertion in MySql DB

Status
Not open for further replies.

kdshah

Programmer
Oct 15, 2002
8
US
I want to have a date (could be of date type or some other type) field in mysql database which would store an expiry date. This date is entered by the user and is sent to the PHP script as a querystring of the form mm/dd/yyyy and this value is then to be stored in the mysql table.

Now, I would like to add 30 days to the current time if this value is not entered by the user. This can be thought of as a default expiry date which is 30 days from the current date.

Keeping this in mind, what would be the ideal datatype that i should be using in Mysql database. I'LL NEED TO COMPARE THIS VALUE WITH THE CURRENT DATE everytime I lookup something in that table, TO CHECK WHETHER THE EXPIRY DATE HAS PASSED .

Guide me on this.

Thanks,
Kunal
 
Use MySQL's builtin date_add() function.

You're PHP code will know whether a date was added or not. If it was, just insert it. If not, an update query like:

update foo set stamp = date_add(now(), interval 30 day) where id = 2

should do the trick ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top