Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

How to Insert date from string: CAST vs CONVERT?

Asked by Ankesh Kumar Apr 24, 2021 1.2K views 1 answer
Share

About this question

 Consider the following two ways to convert a DateTime varchar string into a date field: SELECT convert(date, '2012-12-21 21:12:00', 20) -- Only date is needed SELECT cast('2012-12-21 21:12:00' as date) -- Only date is needed Both return what I expect: The date excluding the time, in as a date datatype. My question is: Is there any pro and cons of doing either way?

Your answer

1 Answer

More SQL Server discussions