DATETIME to DATE and TIME
SELECT GETDATE(), CONVERT(DATE, GETDATE()), CONVERT(TIME(0), GETDATE()), CAST(GETDATE() AS DATE)
Should I use CAST or Convert?
Unless you have some specific formatting requirements you’re trying to address during the conversion, I would stick with using the CAST function. There are several reason I can think of:
- CAST is ANSI-SQL compliant; therefore, more apt to be used in other database implementation.
- There is no performance penalty using CAST.
- I think CAST is easier to read, and since it is part of the ANSI specification, your non-SQLServer DBA think so too!
Sources:
https://www.essentialsql.com/what-is-the-difference-between-cast-and-convert/
Comments