SQL Server 2008 has introduced the new Date and Time data types. Now assigning a date to time data type will return only the time part of the datetime and the Date will return the Date part of the datetime ...
DECLARE @datetime AS DATETIME = getdate();
DECLARE @date AS DATE = @datetime;
DECLARE @time AS TIME = @datetime;
SELECT @date, @datetime, @time
Result is:
2012-07-01 2012-07-01 10:40:06.403 10:40:06.4030000
Or alternatively:
SELECTCONVERT(TIME,GETDATE()) AS HourMinuteSecond,CONVERT(DATE,GETDATE()) AS DateOnly
GO
Or to get only the HH:MM then as follow:
DECLARE @time AS TIME(0) = @datetime; -- With zero precision so returns hh:mm
'via Blog this'
Popular Posts
-
Kendo UI applying SUM in footer template kendo ui - KendoUI: Grid Summary values in Footer - Stack Overflow : ", footerTemplate:...
-
MVC grid example ASP.NET MVC Flexigrid sample - CodeProject : 'via Blog this'
-
A possible way of handling distributed transaction for multiple contexts without alleviation to MSDTC??? c# - Entity Framework - Using Trans...
No comments:
Post a Comment