Cast Datetime To Date Sql Code Example


Example 1: sql datetime as date

SELECT      CONVERT(DATE, GETDATE()) date;

Example 2: sql server convert string to date

Cast( '2011-07-07' as date ) as convertedDate

Example 3: sql cast date

DECLARE @counter INT = 0 DECLARE @date DATETIME = '2006-12-30 00:38:54.840'  CREATE TABLE #dateFormats (dateFormatOption int, dateOutput nvarchar(40))  WHILE (@counter <= 150 ) BEGIN    BEGIN TRY       INSERT INTO #dateFormats       SELECT CONVERT(nvarchar, @counter), CONVERT(nvarchar,@date, @counter)        SET @counter = @counter + 1    END TRY    BEGIN CATCH;       SET @counter = @counter + 1       IF @counter >= 150       BEGIN          BREAK       END    END CATCH END  SELECT * FROM #dateFormats

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?