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 |
|
michpaust
Starting Member
21 Posts |
Posted - 2005-05-10 : 09:54:16
|
| I need a way to convert date to an integer. I have a query in which I am subtracting two dates, one from the other and I need the answer to show up as an int and not a date itself. I am drawing a blank here. Here is an extract of the code that I need to change,(d_item1.date_create-d_invitem.shipment_date) as Release_vs_Delivered,(isnull(d_poitem3.more_dates_8,d_poitem3.delivery_date)-d_invitem.shipment_date)as Release_vs_Promise,(isnull(d_poitem3.more_dates_8,d_poitem3.delivery_date)-d_item1.date_create)as gap,(case when(isnull(d_poitem3.more_dates_8,d_poitem3.delivery_date)-d_item1.date_create)<0 then '0'else '1'end)as score Any help would be appreciated.--I don't suffer from insanity. I enjoy every minute of it.-- |
|
|
RM
Yak Posting Veteran
65 Posts |
Posted - 2005-05-10 : 10:07:38
|
| check out the DateDiff function |
 |
|
|
elwoos
Master Smack Fu Yak Hacker
2052 Posts |
Posted - 2005-05-10 : 10:08:58
|
If you want the number of days between two dates you may find that DATEDIFF does what you want e.g. (from BOL)USE pubsGOSELECT DATEDIFF(day, pubdate, getdate()) AS no_of_daysFROM titlesGO returns the number of days between pubdate and todaysteveA sarcasm detector, what a great idea. |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-05-10 : 10:09:29
|
This will do what you want, it returns a difference between two dates in days:select datediff(day,d_item1.date_create,d_invitem.shipment_date) CODO ERGO SUM |
 |
|
|
elwoos
Master Smack Fu Yak Hacker
2052 Posts |
Posted - 2005-05-10 : 10:09:36
|
| eek! simultaneous postings!!!A sarcasm detector, what a great idea. |
 |
|
|
michpaust
Starting Member
21 Posts |
Posted - 2005-05-10 : 11:01:17
|
| Thank you so much. The date diff works perfectly!--I don't suffer from insanity. I enjoy every minute of it.-- |
 |
|
|
|
|
|
|
|