开发者

What is the most convenient way to generate datetime in SQL?

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())

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜