| Author |
Topic  |
|
|
peace
Constraint Violating Yak Guru
283 Posts |
Posted - 05/10/2012 : 22:33:37
|
How can I get the date for 3 days before today?
Example today's date 11 May. I would like to get 8,9,10 May.
select ... from ... where CONVERT(date,goDate)=DATEADD(Day,-1, datediff(day, 0,getdate()) ) |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
48012 Posts |
Posted - 05/10/2012 : 22:35:37
|
SELECT *
FROM table
WHERE goDate>=DATEADD(Day,datediff(day, 0,getdate()),-3)
AND goDate< DATEADD(Day,datediff(day, 0,getdate()),0)
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
peace
Constraint Violating Yak Guru
283 Posts |
Posted - 05/10/2012 : 22:39:51
|
| Oh got it thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
48012 Posts |
Posted - 05/10/2012 : 22:49:07
|
wc
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
madhivanan
Premature Yak Congratulator
India
22469 Posts |
|
|
peace
Constraint Violating Yak Guru
283 Posts |
Posted - 05/15/2012 : 02:47:12
|
| how can i get data for every 1st of every month, of the previous month? |
 |
|
|
peace
Constraint Violating Yak Guru
283 Posts |
Posted - 05/15/2012 : 05:07:43
|
I get this but it return for this month. How to get for previous month?
select dateadd(month,datediff(month,0,getdate()),-0) as first_day_of_month select dateadd(month,datediff(month,0,getdate())+1,-1) as last_day_of_month |
 |
|
|
webfred
Flowing Fount of Yak Knowledge
Germany
8529 Posts |
Posted - 05/15/2012 : 05:17:19
|
Select DateAdd(Month,DateDiff(Month,0,getdate())-1,0) as firstday,
DateAdd(dd,-1,DateAdd(Month,DateDiff(Month,0,getdate()),0)) as lastday
No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
48012 Posts |
Posted - 05/15/2012 : 22:04:18
|
quote: Originally posted by peace
I get this but it return for this month. How to get for previous month?
select dateadd(month,datediff(month,0,getdate()),-0) as first_day_of_month select dateadd(month,datediff(month,0,getdate())+1,-1) as last_day_of_month
the part in blue is one which calculates the month elapsed since start of base date (1900). the current way it returns month count till current month because of getdate. you can subtract 1,2,3 etc depending how many months before you want to traverse from current month
see this also to see similar date logics
http://visakhm.blogspot.com/2010/01/some-quick-tips-for-date-formating.html
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
madhivanan
Premature Yak Congratulator
India
22469 Posts |
Posted - 05/16/2012 : 04:21:43
|
quote: Originally posted by peace
I get this but it return for this month. How to get for previous month?
select dateadd(month,datediff(month,0,getdate()),-0) as first_day_of_month select dateadd(month,datediff(month,0,getdate())+1,-1) as last_day_of_month
Have you seen the link I posted? Loot at the examples shown as last page
Madhivanan
Failing to plan is Planning to fail |
 |
|
| |
Topic  |
|