how to calculate days between two dates?

hello all, i m working with some application where i want to post an email on calculated date which is from some table in database.

i just want to calculate the days between two dates one is getdate() and second is getdate()-14 days..

plz guide me on this..

thx 


0
fakhre
7/9/2008 9:22:38 AM
📁 asp.net.sql-datasource
📃 29906 articles.
⭐ 0 followers.

💬 3 Replies
👁️‍🗨️ 473 Views

If second date is getdate()-14 days, then you must already know that there is 14 days diff?

Or are you trying to calculate the starting date? If that's the case, you need to use the DATEADD function in T-SQL:

SELECT DATEADD(day, -14, GETDATE()) AS STARTDATE, GETDATE() AS ENDDATE
 

If this post was useful to you, please mark it as answer. Thank you!
0
johram
7/9/2008 10:22:54 AM

johram:
If second date is getdate()-14 days, then you must already know that there is 14 days diff?

johram replied already you know the actual differance between two dates then .. what days needs to be calualted?

might be you are trying to calucalte the date difference between two dates.

SELECT DateDiff( DD,DATEADD(day,-14,GetDATE()),'2008-07-05')

DateDiff( DD,<StartDate>,<End Date>)


Regards,
Sasi

Please remember to click "Mark as Answer" on this post if it helped you.
0
sasi
7/9/2008 10:33:03 AM

SELECT [yourcolumn list] FROM yourTable

WHERE dtColumn>DateAdd(second, -1, DateAdd(day, DateDiff(day, 0, getdate()), 0))

AND dtColumn<=DateAdd(second, -1, DateAdd(day, DateDiff(day, 0,getdate()), 14))  --Change this number for days.


Limno

0
limno
7/9/2008 1:25:24 PM
Reply: