Lerner Zhang
0
Q:

sql cast date

CAST('2006-04-25T15:50:59.997' AS date) AS Date,  

CAST('2006-04-25T15:50:59.997' AS time) AS Time,  

CAST('2006-04-25T15:50:59.997' AS datetime) AS Datetime, 
2
-- NOTE: this is for SQL-Oracle specifically

/*
<...> : Your personal entry
*/

-- syntax:
CAST(<variable> as <variable-type>) -- in this case: <variable-type> = INTEGER

-- example:
SELECT CAST(MEMBER_NO as INTEGER)
FROM DUAL;
4
-- Specifically for Oracle

-- EXAMPLE
CAST('732.98' AS INT)

/* SYNTAX
CAST(<value_to_cast> AS <data_type_to_cast_to>)
*/
2
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
0

  SELECT 
  CAST("2017-08-29" AS DATE); 
0

SELECT CAST('2017-08-25' AS datetime); 
0

New to Communities?

Join the community