Link to home
Start Free TrialLog in
Avatar of maatayim
maatayim

asked on

MySQL DateTime NOW() as the default value

Hey there,
need some help with setting my default value in a table to the current datetime
for some reason i cant get the NOW() function to work if i use the DATETIME type.
however, when i use TIMESTAMP type and CURRENT_TIMESTAMP it work!

any ideas how can i get the DATETIME type working?
thanks ahead,
Dan
Capture.PNG
Avatar of Cornelia Yoder
Cornelia Yoder
Flag of United States of America image

A mysql function cannot be used as a default.  You will need to use TIMESTAMP field or enter NOW() as part of the values in an INSERT.
Avatar of maatayim
maatayim

ASKER

hi there,
correct me if i'm wrong but timestamp has a differnt way of recording time.
from what i understood the time is being kept in utc and when i retrive is from the data base is converts it back to my timezone.
this could be problematic if u work with servers world wide and try to keep track of dates and times...

is there a ways of using it and still read the real UTC time?
thanks
Dan
To convert any date requires you know the time zone of the end user.  That means client-side code, and there are javascript functions that can do that for you.  But it would still be stored in the database as UTC.

http://www.fruitnotes.com/blogs/Javascript_-_converting_unix_timestamp_to_locat_time_format_758

ASKER CERTIFIED SOLUTION
Avatar of SoLost
SoLost
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial