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)
 Difference in dates

Author  Topic 

scelamko
Constraint Violating Yak Guru

309 Posts

Posted - 2007-07-12 : 16:18:20
Guys,

I need to find out a way to display all dates between current date - getdate() and give date say '2007-07-03'.

Is there any way to do this, I tried DATEADD, DATEDIFF, DATEPART doesnt seem to work.

Any suggestions and inputs would help

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-12 : 16:29:08
Try harder! DateDiff works.
Are you using MICROSOFT SQL Server? Have you read Books Online?



Peter Larsson
Helsingborg, Sweden
Go to Top of Page

scelamko
Constraint Violating Yak Guru

309 Posts

Posted - 2007-07-12 : 16:34:50
Peso,

I am trying to get a result where I get dates between getdate() and '2007-07-09' as

2007-07-10
2007-07-11

All I get now with DATEDIFF is a number.

Any suggestions would help

Thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-12 : 16:38:40
You want the "median" date? It is a very popular subject these days.
Try a search http://www.google.com/search?hl=en&rls=com.microsoft%3Aen-US&q=median+date+site%3Asqlteam.com&btnG=Search

Or use
DATEADD(HOURS, DATEDIFF(HOURS, '20070709', current_timestamp) / 2.0, '20070709')


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-12 : 16:45:48
quote:
Originally posted by scelamko

Peso,

I am trying to get a result where I get dates between getdate() and '2007-07-09' as

2007-07-10
2007-07-11

Aha! You want a resultset with all days in the calendar between some date and another date?

Look for a function named F_TABLE_DATE written by Michael Valentine Jones. It has everything and some more of what you need and want.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-12 : 16:46:37
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61519


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

scelamko
Constraint Violating Yak Guru

309 Posts

Posted - 2007-07-13 : 13:25:45
Thanks Peso that did the trick.
Go to Top of Page
   

- Advertisement -