1. Learn
  2. /
  3. Courses
  4. /
  5. Time Series Analysis in SQL Server

Connected

Exercise

Formatting dates with CAST() and CONVERT()

We can use the CAST() function to translate data between various data types, including between date/time types and string types. The CONVERT() function takes three parameters: a data type, an input value, and an optional format code.

In this exercise, we will see how we can use the CAST() and CONVERT() functions to translate dates to strings for formatting by looking at the (late) night the Chicago Cubs won the World Series in the US in 2016. In the process, we will see one difference between the DATETIME and the DATETIME2 data types for CAST() and the added flexibility of CONVERT().

Instructions 1/4

undefined XP
    1
    2
    3
    4
  • Fill in the appropriate function, CAST(), for each example.
  • Using the aliases as a guide, fill in the appropriate variable for each example.