Reputation: 13
I'm trying to count days left and days passed in my database. I have A day for Deadline and a day as Start Day on my table and this counting must compare from #todays date#. In the table I have 10000 records that is impossible to count by hand.
Upvotes: 0
Views: 1218
Reputation: 1485
I'm not sure but I guess what you are looking for is DATEDIFF()
function.
So your code would be like:
SELECT DATEDIFF(DAY,[StartDate],GETDATE()) AS CountDaysPassed,
DATEDIFF(DAY,GETDATE(),[EndDate]) AS CountDaysLeft
FROM MyTable
This is if you have Date as your start date and deadline (end date). But If you have days (integer, like 10 days) as your deadline your calculation should be like:
SELECT DATEDIFF(DAY,GETDATE(),(DATEADD(DAY,[DeadlineDays],[StartDate]))) AS CountDaysLeft
FROM MyTable
Upvotes: 1