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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Begin and last date of last month

Author  Topic 

Sian
Starting Member

2 Posts

Posted - 2005-05-26 : 03:36:23
My application has to run a query which period is between the start date and the last date of the previous month. Example: today 26/05/2005. The dates will be "Between 01/04/2005 and 30/04/2005"
How can I write the script in SQL? Thanks in advance. Sian

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2005-05-26 : 03:46:47
WHERE DateDiff(m, YourDate, GetDate()) = 1

Breaking that down :

DateDiff gives the difference between two dates
the "m" means month (i.e. the number of months difference)
GetDate() gives the current date.

Any date in last month with have a difference of one month from todays date.

Look up DateDiff in Books Online for more syntax.


Damian
Ita erat quando hic adveni.
Go to Top of Page

Sian
Starting Member

2 Posts

Posted - 2005-05-26 : 05:38:25
Hi Damian, thanks for your help. It works well.
Sian.
Go to Top of Page
   

- Advertisement -