0% found this document useful (0 votes)
50 views

Handout 6 - Lecture Notes

This document discusses date functions in SQL including DateAdd, DateDiff, and Datepart. DateAdd can be used to add or subtract months from a date field. DateDiff finds the number of years or months between two dates. Datepart extracts parts of a date like week number, day number, day of year, and weekday number from a date.

Uploaded by

abdi
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Handout 6 - Lecture Notes

This document discusses date functions in SQL including DateAdd, DateDiff, and Datepart. DateAdd can be used to add or subtract months from a date field. DateDiff finds the number of years or months between two dates. Datepart extracts parts of a date like week number, day number, day of year, and weekday number from a date.

Uploaded by

abdi
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Lecture notes/class exercises – Handout 6

DateTime Functions

1 DateAdd
Add 2 months to titles.pubdate
Show how this can also be used to subtract from a date – subtract 1 month from the
pubdate (use a negative value for the number paramter)

2 DateDiff
Find how many years since each title was published
Find how many months since each title was published

3 Datepart
Find the week number of the current date
Find the day number for the current date
Find the day of year number for the current date
Find the week day number for the current date
(point out the difference between day, dayofyear and weekday – day is 1-31,
dayofyear is 1 – 366, weekday is 1-7)

You might also like