Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 GetDate() question

Author  Topic 

dardar
Starting Member

10 Posts

Posted - 2012-01-19 : 03:36:52
hi all.
i need to make a query that can ask if a date is earlier than last month.

how can i get "last month" value?
for now i'm using GETDATE() - 30 , but of course this is not so accurate.

is there any other way to decrease a month for the current date?

ty

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-01-19 : 03:46:39
DATEADD(mm,-1,GETDATE())

--
Gail Shaw
SQL Server MVP
Go to Top of Page

dardar
Starting Member

10 Posts

Posted - 2012-01-19 : 04:34:24
thx alot.
i saw in the MSDN ducumenatation that u can use "mm" or "m" AS Abbreviation for month.
what is the diffrence?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-01-19 : 05:00:54
How exactly do you define "earlier than last month"?


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

sql-programmers
Posting Yak Master

190 Posts

Posted - 2012-01-19 : 05:24:11
mm, m, month... All are same .....

select DATEADD(mm,-1,GETDATE())
select DATEADD(m,-1,GETDATE())
select DATEADD(MONTH,-1,GETDATE())

SQL Server Programmers and Consultants
http://www.sql-programmers.com/
Go to Top of Page
   

- Advertisement -