SQL beginner here !
What is the most convenient way to create datetime objects within an SQL function, especially generating a datetim开发者_运维知识库e object for a given day, month, and year?
Thanks !
Everything you want to know about MySQL datetime functions is right here. Well, probably most everything.
In MySQL
CAST('YYYY-MM-DDThh:mm:ss:uuuuuu' AS datetime)
where:
YYYY: Year
MM : Month
DD : Day
hh : Hour
mm : Minutes
ss : Seconds
uuuuuu : Microseconds
EDIT: I changed from mmm (miliseconds) to uuuuuu (microseconds) since MySQL suports 6 digits
Given a datetime column: INSERT INTO Table ('datetime_column') VALUES (CURDATE( ))
Given a timestamp: INSERT INTO Table ('timestamp_column') VALUES (CURTIME())
Using unix time: INSERT INTO Table ('timestamp_column') VALUES (UNIX_TIMESTAMP())
精彩评论