I want to save time in my SQL Server database in this format:
hh:mm
and not this:
hh:mm:ss
Is that possible? Is there a unique data type for that (I tried to go over the list of data types but failed to find; tried also to search on MSDN and didn't find). Is there another way? I really do not want the second to be stored.
You will need to use two fields to store an interval e.g. [time_span_start] and [time_span_end]. The difference between the two will give you the interval. Save this answer.
In SQL Server, ROWVERSION and TIMESTAMP data types represent automatically generated binary numbers, unique within the database. ROWVERSION and TIMESTAMP are synonyms, ROWVERSION is available since SQL Server 2005, while TIMESTAMP is deprecated and will be removed in a future version of SQL Server .
Use Format function available from SQL Server 2012
select format(getdate(),'hh:mm')
Insert into sometable
(timepart)
values
(
format(getdate(),'hh:mm'))
Output:
07:08
No there isn't a data type for this. The smallest is time(0), which is accurate to one second.
SELECT
-- Returns time in the format hh:mm:ss
CAST(GETDATE() AS TIME(0))
;
You could add a check constraint to ensure the seconds are always equal to 00, but I'm not sure what value this would add.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With