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 |
|
gavakie
Posting Yak Master
221 Posts |
Posted - 2008-04-30 : 09:16:27
|
| I have a columns with storeID's and dates i need to be able to find the difference of date for a certain store for its Min(Date) to the End of that Monthexample Date StoreID Difference of Date to end of the Month2008-01-02 00:00:00.000 1632008-01-03 00:00:00.000 1652008-01-01 00:00:00.000 1672008-01-02 00:00:00.000 180 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-30 : 09:24:41
|
[code]DECLARE @Sample TABLE (Date DATETIME, StoreID INT)INSERT @SampleSELECT '2008-01-02', 163 UNION ALLSELECT '2008-01-03', 165 UNION ALLSELECT '2008-01-01', 167 UNION ALLSELECT '2008-01-02', 180SELECT *, DATEDIFF(DAY, Date, DATEADD(MONTH, DATEDIFF(MONTH, '18991231', Date), '18991231')) AS DifferenceFROM @Sample[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2008-04-30 : 09:26:47
|
| [code]select getdate() ,(datediff(day, getdate(), dateadd(month, datediff(month, -1, (getdate())), 0)))-1 as diff_till_end_of_month[/code] |
 |
|
|
|
|
|
|
|