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.
| Author |
Topic |
|
Amber_Deslaurier
Starting Member
40 Posts |
Posted - 2010-07-18 : 12:32:19
|
| Hi,I have an automation process in place and I need SQL to know which dates to use.I would like the code to select:Current YEAR, MONTH and DAY. Example: 2010-07-18 BUT to MINUS it BY 2 days (INTERVAL DAY 2)since the database may have data that is recasted after a day or so when its a new month I will always have the latest data from the previous month...Is there an easy way to do this?Thanks,Amber- |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-07-18 : 12:40:39
|
| Are you looking for this ?SELECT DATEADD(day, DATEDIFF(day, 0, GETDATE()) -2 , 0) |
 |
|
|
Amber_Deslaurier
Starting Member
40 Posts |
Posted - 2010-07-18 : 12:59:32
|
| Thanks, I think so... I will have to test it. But what if I needed the first day of the current month... would it be: SELECT DATEADD(day, DATEDIFF(day, 0, GETDATE()) , 0) ? |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-07-18 : 13:30:30
|
select dateadd(m,datediff(m,0, getdate()),0) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
|
|
Amber_Deslaurier
Starting Member
40 Posts |
Posted - 2010-07-18 : 14:41:43
|
| THANKS! |
 |
|
|
|
|
|
|
|