user549757
user549757

Reputation: 33902

Store timestamp value in SQL Database

What is actually stored in Timestamp field in the SQL?

My requirement is to only store the time value like 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.

And when I pass entire date, it accepts.

Is there any way to only give time to timestamp field or date is required there?

Upvotes: 0

Views: 4531

Answers (2)

eumiro
eumiro

Reputation: 212835

Timestamp contains both date and time. For time only try TIME column type.

Upvotes: 3

seppo0010
seppo0010

Reputation: 15849

Timestamp is a date with time. It's the usual name for the number of seconds since 1970-01-01 00:00:00 GMT.

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

Upvotes: 2

Related Questions