In SQL Server 2008, the time data type has an optional precision argument (default is 7). In this case, you can control how many fractional decimal places are stored and displayed.
DECLARE @time time(3) SET @time = GETDATE() PRINT @time
The above will print this,
10:47:25.347
The documentation indicates the least precision time(0) . This will save and print 10:47:25 .
Is it possible to further reduce accuracy to exclude / disable seconds: 10:47 ?
I know this can be done manually by adding a constraint ( DATEPART(seconds, @time) = 0 ), doing the math when entering data to zero seconds and manually formatting when printing, but I'm looking for an easier way to simply define the field in the table as " hours and minutes, "in much the same way as the date type allows you to define a field as" just a date, not a time. "
sql time precision sql-server-2008
David
source share