Sqlserver
 SQL >> Database >  >> RDS >> Sqlserver

Contare i giorni di un mese con SQL Server

Da SQL Server 2012 in poi puoi combinare EOMONTH e DAY:

DECLARE @ADate DATETIME
SET @ADate = GETDATE()
SELECT DAY(EOMONTH(@ADate)) AS DaysInMonth

Nelle versioni precedenti si può ottenere lo stesso risultato calcolando il primo giorno del mese successivo e sottraendo un giorno.