View Full Version : Saving Dates in mysql
d-machine
09-29-2013, 08:32 AM
Hi,
I want to save the date of 10 days after the current date in my MySQL DB.
For example:
if today is 29/09/2013 I want to save in my db the date: 09/10/2013
How can I do it?
Thanks!
djr33
09-29-2013, 09:24 AM
This is a several step process.
You can get the current time using:
time()
Then you can add 10 days:
time() + 60*60*24*10
Then you can use that value (save it in a variable) in the date function:
date('FORMAT',$savedtime)
Replace "format" with the appropriate format (anything you want, see the php.net manual for more info).
However, in general it's a bad idea to save dates in a human-readable format in a database. Instead, just save the timestamps. Then do whatever you want with them in PHP-- and format them, using date(), when you display them.
Doing math on raw dates is confusing and indirect. But doing math on timestamps is easy.
By the way, if you do happen to need to convert a string/description/text to a timestamp, then you can use:
strtotime()
By the way, if you do happen to need to convert a string/description/text to a timestamp, then you can use:
strtotime()
Like
$timestamp = strtotime( '10 days' ); :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.