Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I am facing a problem. When I run this below SQL statement in the SQL Server 2012:

TO_DATE('2011-11-09 00:00:00','YYYY-MM-DD HH24:MI:SS')

I am getting the following error:

'TO_DATE' not is a name de function integrate recognized.

Can anyone help with this?

1 Answer

0 votes
by (12.7k points)
edited by

The SQL-Server does not have any TO_DATE function. You need to use the convert.

-- Specify a datetime string and its exact format
SELECT TO_DATE('2012-06-05', 'YYYY-MM-DD') FROM dual;


-- Specify a datetime string and style 102 (ANSI format), raises an error if conversion fails
  SELECT CONVERT(DATETIME, '2012-06-05', 102);

  -- TRY_CONVERT available since SQL Server 2012 (returns NULL if conversion fails)
  SELECT TRY_CONVERT(DATETIME, '2012-06-05', 102);

For your particular case you can use:

convert(DATETIME, '2011-11-09 00:00:00')

Want to be a SQL expert? Join the SQL Training program by Intellipaat to learn more.

Related questions

0 votes
1 answer
asked Dec 30, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...