convert date in sql code example
Example 1: sql to date
SELECT TO_DATE('2012-06-05', 'YYYY-MM-DD') FROM dual;
SELECT TO_DATE('05/06/2012 13:25:12', 'DD/MM/YYYY HH24:MI:SS') FROM dual;
SELECT CONVERT(DATETIME, '2012-06-05', 102);
SELECT TRY_CONVERT(DATETIME, '2012-06-05', 102);
SELECT STR_TO_DATE('2012-06-05','%Y-%m,%d');
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
WHILE (@counter <= 150 )
BEGIN
BEGIN TRY
INSERT INTO
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