SQL Server And Dates

Posted On: In: Microsoft SQL Server

Dates are one of the things I find myself googling more than anything else when writing queries, so I thought I would write a post with a few examples on how to get different combinations of date for use in your queries.

Let’s say we have a date and we want to get just the month, or the week or even just the year, how can we do that?

You see, the Month, Week & Year have been split from the DATETIME column and returned as their seperate values.

Let’s see what other manipulation we can do with dates

First Day Of Current Week

Last Day Of Current Week

First Day Of Last Week

Last Day Of Last Week

First Day Of Next Week

Last Day Of Next Week

First Day Of Current Month

Last Day Of Current Month

First Day Of Last Month

Last Day Of Last Month

First Day Of Next Month

Last Day Of Next Month

First Day Of Current Year

Last Day Of Current Year

First Day Of Last Year

Last Day Of Last Year

First Day Of Next Year

Last Day Of Next Year

Current Year

Current Month

Current Week Number

Current Day In Month

Get Week Day Name

Get Week Day

Date 30 Days Ago

Date 30 Days Future

There are so many other things you can do with dates this is just the tip of the ice berg, but hopefully it will help you get started in working with dates on SQL Server.