SQL Queries||How to get First and Last Dates of Month and Number of days in Month?

Опубликовано: 29 Сентябрь 2024
на канале: LearnSQLtoSSIS
63
2

DECLARE @FirstDate Date
DECLARE @LastDate Date
DECLARE @NumberofDays INT

SET @FirstDate = DATEADD(month,DATEDIFF(month,0,getdate()),0) --FirstDate
SET @LastDate = EOMONTH(getdate()) --LastDate
SET @NumberofDays = DAY(EOMONTH(getdate())) --Numberofdays

SELECT @FirstDate First_Date,
@LastDate AS Last_Date,
@NumberofDays TotalDaysInMonth