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
 dates

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 Month

example

Date StoreID Difference of Date to end of the
Month
2008-01-02 00:00:00.000 163
2008-01-03 00:00:00.000 165
2008-01-01 00:00:00.000 167
2008-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 @Sample
SELECT '2008-01-02', 163 UNION ALL
SELECT '2008-01-03', 165 UNION ALL
SELECT '2008-01-01', 167 UNION ALL
SELECT '2008-01-02', 180

SELECT *,
DATEDIFF(DAY, Date, DATEADD(MONTH, DATEDIFF(MONTH, '18991231', Date), '18991231')) AS Difference
FROM @Sample[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

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]
Go to Top of Page
   

- Advertisement -