开发者

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

开发者 https://www.devze.com 2022-12-10 21:25 出处:网络
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?

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

精彩评论

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

关注公众号