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 |
|
csphard
Posting Yak Master
113 Posts |
Posted - 2007-06-13 : 11:15:37
|
| I want to subtract a date from the current date.I want to use datediff but I see that the datepart is the date broken down to it parts and not the whole date. What do I use to do the following getdateI() - myDate.Howard |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-13 : 11:16:56
|
quote: I want to subtract a date from the current date.
you want the different of 2 dates in terms of days ? hours ? or ? KH |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-06-13 : 11:21:03
|
| select getdateI() - @myDatewill do the subtraction.It will give the result as a datetime which you can format as you wish.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
csphard
Posting Yak Master
113 Posts |
Posted - 2007-06-13 : 11:28:05
|
| In terms of days. I did not understand date. The following worked.So by say day I told it to give me the number of days right?datediff(day,payloc_comp_date,getdate()) |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-06-13 : 11:36:01
|
| Yep - that will give the number of midnights between the two dates.Might be different (by 1) fromdatepart(dd, getdate()-payloc_comp_date) if you have a time in the date.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-13 : 11:38:19
|
Yes. datediff(day,payloc_comp_date,getdate()) will give you the number of days different between the 2 dates KH |
 |
|
|
csphard
Posting Yak Master
113 Posts |
Posted - 2007-06-13 : 11:51:11
|
| Thanks everyoneHoward |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
|
|
|
|
|