visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Databases :: MySql :: Date time data type


By: PHP newbee U.S.A.  Date: 24/09/2004 00:00:00  English  Points: 50 Status: Answered
Quality : Excellent
Dear all,
In MySQL, I want to store a datetime value.
My datetime value include: year, month, day, hour, minute, seconds, milisecond.
How can I store this value because currently datetime data type of MySQL does not support milisecond??

Thank you and best regards,
By: VGR Date: 24/09/2004 16:50:00 English  Type : Answer
simple :
1) either drop the millisecond value 8-)
2) goto 1)

:D

Even UNIX_TIMESTAMP function returns number of SECONDS since epoch0

kidding 90% :D

3) store yourself the value in a char(18) as YYYY-MM-DD HH:MM:SS:mmm

Don't forget to add an index in case you want to query on it as key
By: psadac Date: 25/09/2004 19:00:00 English  Type : Comment
4) use BIGINT to store unix timestamp * 1000

with FROM_UNIXTIME() and UNIX_TIMESTAMP() functions.

<A HREF="http://www.mysql.com/doc/en/Date_and_time_functions.html">http://www.mysql.com/doc/en/Date_and_time_functions.html</A>

should be faster with indexes.

5) use PostgreSQL
By: VGR Date: 25/09/2004 19:14:00 English  Type : Comment
4) is a good hack :D

BUT I looked in the UNIX_TIMESTAMP() function, of course :D and I found it returning no millisecond part. At least that's what the MySql documentation says...
By: psadac Date: 25/09/2004 19:25:00 English  Type : Assist
i haven't verified but you must have a modulo (%) function in mysql ?
so field % 1000 will give you the milliseconds.
i know it's not very practical but you can't define user functions in mysql, that's the reason of 5)
By: VGR Date: 25/09/2004 19:32:00 English  Type : Comment
4) they will be zero !

if there's no milliseconds returned by unix_timestamp (as I think it is), they storing that*1000 and then doing a modulo 1000 will just display 0 as milliseconds...

If the raw data isn't there, you can't do anything.

On the other side, mktime() in PHP has ability to get milliseconds and even fractions , so it's always possible to use a BIGINT or a FLOAT or a CHAR(15+) to store the "normal DATETIME format"+a part of the milliseconds. But not in MySql itself IMHO

Do register to be able to answer

EContact
browser fav
page generated in 447.407960 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page