PDA

View Full Version : Registering dates and time in MySQL


Jeewhizz
07-08-2003, 01:54 AM
Registering dates and time : date, time, datetime, year and timestamps columns

A lot of people have problems with storing and displaying dates.
The best way to avoid these is by choosing the right column-type. For example, if you only need the date, then don't use a datetime column and spare yourself the hassle of extracting the date from the datetimevalue. You'll find a complete overview of all datetime-columntypes at http://www.mysql.com/doc/en/Date_and_time_types.html

For these stored date/datetime/timestamp - values, there are a lot of functions to convert or extract parts of the values and respond them in the format that you need them. You'll find a complete overview of these functions at http://www.mysql.com/doc/en/Date_and_time_functions.html

It's important to note that these are MySQL function, which can be used inside sql-statement that are processed by the MySQL server. All these functions can be used from the command-line, in embedded sql (query's inside ASP, PHP, JSP, ...) or database-front-ends.

Within each serverside language, there are some (or a lot) of
date/datetime/timestamp functions.

for PHP : http://www.php.net/datetime
for ASP : http://www.4guysfromrolla.com/webtech/110398-1.shtml (VBscript)
and
http://www.haneng.com/FunctionSearch.asp?s=a (for all VBscript
functions)

Create by: raf

freakysid
05-19-2004, 05:42 PM
It is also important to understand the behaviour of the MySQL TIMESTAMP type. When a table contains a column of type TIMESTAMP and a row in that table is updated in an UPDATE or REPLACE query, the value of the TIMESTAMP element in that row will also be updated to the current server time unless the query explicitly sets the value of a TIMESTAMP element.

http://dev.mysql.com/doc/mysql/en/TIMESTAMP_pre-4.1.html

raf
05-20-2004, 09:03 AM
it's actualy updated on on UPDATE or INSERT query. The REPLACE is just a regular insert, with the extra that on key violation, the original record is first deleted, and then the new record is inserted.

About the automatic update : this is only true for the first column of type timestamp. All folowing columns of type timestamp will not be updated.

bethafin2000
03-11-2005, 07:23 AM
...but can anyone shed any light to my ADDTIME question posted yestrday?

Thanks!
Beth