233k views
5 votes
If ExpirationDate contains a value that's equivalent to June 2, 2016 and the GetDate function returns a value that's equivalent to July 17, 2016, what will the Solution column contain when this code is executed?

DATEDIFF(day, ExpirationDate, GetDate()) AS Solution

A)1
B)15
C)30
D)45

1 Answer

4 votes

Answer:

D)45

Step-by-step explanation:

DATEDIFF() function basically returns the difference between two specified dates.

This function has three parameters:

  • interval or date part which can be one of the following: day, year, month, quarter, week, hour, minute, second.
  • start data
  • end date

The start date and end date are the arguments of the function of which the difference is to be calculated for the specified interval.

So the given statement is:

DATEDIFF(day, ExpirationDate, GetDate()) AS Solution

This statement has a function DATEDIFF() whose parameters are day (interval), ExpirationDate (start date) and GetDate() (end date)

It uses AS which is alias to give a name to the column which produces the result returned by DATEDIFF. So it is given a temporary name Solution.

ExpirationDate contains value equivalent to June 2, 2016

GetDate() is a function which returns a value equivalent to July 17, 2016

DATEIFF() function computes the difference between these two dates i.e. June 2, 2016 and July 17, 2016. This function returns integer value by calculating the difference between June 2, 2016 and July 17, 2016 with the specified interval or unit which is day here.

So the difference between the days from June 2, 2016 to July 17, 2016 is of 45. There are 30 days in June and 31 days in July. If we subtract 17

Now the difference between the days from June 2 to July 17.

17 July - 2 June = 45 days difference.

User Mark Erdmann
by
5.2k points