CAST(CreatedDate AS DATE)
CONVERT(DATE, CreatedDate)

Convert vs Cast

  • CAST and CONVERT are two SQL functions used by programmers to convert one data type to another.
  • The CAST function is ANSI standard and is compatible to use in other databases while the CONVERT function is a specific function of the SQL server.
  • Since the CAST function is compatible with other databases, it is also described as portable though it has fewer features compared to the CONVERT function. The CONVERT function, meanwhile, can do some things that the CAST function cannot.
  • The CAST function is used to convert a data type without a specific format. The CONVERT function does converting and formatting data types at the same time.
  • In terms of syntax, both functions have the optional parameter of length. In the CONVERT function, there is an additional parameter called style which specifies the format of the data type after conversion.
  • The CAST function is often used to preserve decimal values and places while converting them into integers. The function can also truncate the decimal value if needed. The CONVERT function cannot perform this task.

Sources

http://www.differencebetween.net/technology/software-technology/difference-between-cast-and-convert-2/#ixzz7BShRDtUH

https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-ver15

Last modified: November 6, 2021

Author

Comments

Write a Reply or Comment