1. Learn
  2. /
  3. Courses
  4. /
  5. Functions for Manipulating Data in SQL Server

Exercise

Calculating the difference between dates

DATEDIFF() is one of the most commonly-known functions for manipulating dates. It is used for retrieving the number of time units between two dates. This function is useful for calculating, for example:

  • How many years have passed since a specific event.
  • The age of a person at a point in time.
  • How many minutes it takes to process an order in a restaurant.

In almost all business scenarios you can find an example for which using this function proves to be useful.

In this exercise, you will use DATEDIFF() to perform calculations with the dates stored in the voters table.

Instructions 1/2

undefined XP
  • 1

    Calculate the number of years since a participant celebrated their 18th birthday until the first time they voted.

  • 2

    How many weeks have passed since the beginning of 2019 until now?