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

Exercise

Try out type-safe date functions

In this exercise, we will try out the TRY_CONVERT(), TRY_CAST(), and TRY_PARSE() set of functions. Each of these functions will safely parse string data and attempt to convert to another type, returning NULL if the conversion fails. Conversion to, e.g., a date type can fail for several reasons. If the input string is not a date, conversion will fail. If the input type is in a potentially ambiguous format, conversion might fail. An example of this is the date 04/01/2019 which has a different meaning in the United States (April 1, 2019) versus most European countries (January 4th, 2019).

Instructions 1/3

undefined XP
  • 1

    Starting with the TRY_CONVERT() function, fill in the function name and input parameter for each example.

  • 2

    With the prior TRY_CONVERT() solution in mind, use TRY_CAST() to see how they compare.

  • 3

    One of our good dates returns NULL. Use TRY_PARSE() and specify de-de for the German date and en-us for the US date.