简体   繁体   English

在SQL数据库中存储时间戳值

[英]Store timestamp value in SQL Database

What is actually stored in Timestamp field in the SQL? SQL中的时间戳字段中实际存储了什么?

My requirement is to only store the time value like 07:00 PM 我的要求是只存储时间值,例如07:00 PM

And the thing when I store only time value I see error message like 当我只存储时间值时,我会看到类似的错误消息

Incorrect datetime value: '07:00 PM' for column 'MY_TIME' at row 1

I also tried giving 07:00:00 , but it too returns same. 我也尝试给07:00:00,但它也返回相同。

And when I pass entire date, it accepts. 当我超过整个日期时,它接受。

Is there any way to only give time to timestamp field or date is required there? 有什么方法可以只给时间戳记字段指定时间,还是在那里需要日期?

Timestamp contains both date and time. 时间戳记包含日期和时间。 For time only try TIME column type. 对于时间,请仅尝试TIME列类型。

Timestamp is a date with time. 时间戳记是带有时间的日期。 It's the usual name for the number of seconds since 1970-01-01 00:00:00 GMT. 这是自格林尼治标准时间1970-01-01 00:00:00以来的秒数的常用名称。

If you only want to store the time, you should use a column with time type (assuming you are using MySQL, may vary depending on the DB engine you use). 如果只想存储时间,则应使用具有时间类型的列(假设您使用的是MySQL,可能会因所使用的数据库引擎而异)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM