Web Hosting Talk







View Full Version : Storing date in MySQL


Red Star Network
09-16-2005, 02:26 PM
When a record is created in a MySQL database, is the date the record is created automatically stored, or do I have to make a field to store this info?

Burhan
09-16-2005, 04:18 PM
You have to create a field to store this information.

sonic10
09-16-2005, 05:22 PM
Simply create a field in your table:

TIMESTAMP

regards

shoogbear63
09-16-2005, 11:21 PM
Yeah, or you can just do DATE as the variable type and manually enter it, by manually you could just use php's date functions. (I did this on a site where I could only allow one entry into the DB per day and saved on php code over TIMESTAMP).

Philco
09-17-2005, 04:09 AM
Be aware TIMESTAMP will update itself to the current time whenever the record is updated as well as when it is created.

unlucky1
09-18-2005, 08:09 PM
Timestamp is definitely not the way to go. Use the datetime field if it exists.

solidphp
09-18-2005, 09:11 PM
I generally use int(10) and manage the unix timestamp via code.

You could use the PHP time() function to create the timestamp in the first place.

You can then use functions such as date, mktime, strtotime, etc. to manage the timestamp and calc dates.

Content-Type.com
09-22-2005, 12:25 AM
Originally posted by solidphp
I generally use int(10) and manage the unix timestamp via code.

You could use the PHP time() function to create the timestamp in the first place.

You can then use functions such as date, mktime, strtotime, etc. to manage the timestamp and calc dates.

Actually, use the mysql function;


UNIX_TIMESTAMP()


There are several ways you can impliment it. Review the following url for more information;


http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html

michael-lane
09-22-2005, 03:39 AM
Originally posted by Content-Type.com
Actually, use the mysql function;


UNIX_TIMESTAMP()


There are several ways you can impliment it. Review the following url for more information;


http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html

thanks thats really usefull i'll check it out at home later.