Skip to content
Advertisement

Rounding dates to first day of the month

I am using SQL Server 2014 and I am working with a column from one of my tables, which list arrival dates.

It is in the following format:

I am writing a query that would pull data from the above table, including the ArrivalDate column. However, I will need to convert the dates so that they become the first day of their respective months.

In other words, my query should output the above example as follows:

I need this so that I can create a relationship with my Date Table in my PowerPivot model.

I’ve tried this syntax but it is not meeting my requirements:

Advertisement

Answer

If, for example, it is 15th of given month then you subtract 14 and cast the result to date:

But my favorite is EOMONTH which requires SQL Server 2012:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement