Sunday, August 5, 2018

Get the previous dates in SQL server

select dateadd(dd,-x, cast(getdate() as date))
select dateadd(day,-x, cast(getdate() as date))
select dateadd(day,-x, getdate())

-- Replace x with your dates required. x could be - or +

  SELECT DATEADD(m, DATEDIFF(m, 0, GETDATE()), 0)   -- get the month start date

Select EOMONTH(getdate()) -- get last date of the month

No comments:

Post a Comment

Postgress - Read a XML file from a postgress table XML column

SELECT xmltable.* FROM xmldata, XMLTABLE('//ROWS/ROW' PASSING data COLUMNS id int PATH ...