Warm tip: This article is reproduced from stackoverflow.com, please click
sql sql-server

-SQL

发布于 2020-03-27 15:41:46

i'm trying to get the date from the start up to present date and year.

For example:

Date Today Jan 31 , 2020

the result must be

jan 1 - 31 2020 ,

Another example: if the date is june 30, 2020 the result must be

jan 1 - june 30, 2020

Can you help me how to do it ? , i'm planning to use BETWEEN

Questioner
codeSeven
Viewed
33
Cedersved 2020-01-31 16:33
DECLARE @date date = ' 2019-05-01'

SELECT EOMONTH(@date), DATEADD(yy, DATEDIFF(yy, 0, @date), 0)