Click here to Skip to main content
15,922,584 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, is there some way every day to calculate the remaining days? Where the application with the final date in a table and start date would be the current date. In the same table have a field called Remaining days to be updated every day, another alternative would be a function that every day would subtract a value to this field to get to 0. Any suggestions? I have the same ideas of how to be there asking for your help.
Posted

You can try DATEDIFF (Transact-SQL)[^] which returns the count (signed integer) of the specified datepart boundaries crossed between the specified startdate and enddate.

Also have look on some CP Articles & QA[^] on same.
 
Share this answer
 
Comments
Manas Bhardwaj 9-Jul-12 9:29am    
correct +5!
Prasad_Kulkarni 9-Jul-12 23:38pm    
Thank you Manas!
Paulo Jorge Arteiro Soares 9-Jul-12 9:36am    
ty i'll try that... is there a way to get the current date in sql? because i need it to count the remaining days.
Prasad_Kulkarni 9-Jul-12 23:39pm    
That's what I have answered. DATEDIFF function can solve your problem. Have a look on it.
Suvabrata Roy 10-Jul-12 0:59am    
In SQL Server Current Date = GetDate()
In SQL, use datediff(dd, getdate(), [last_date_column]). You can add it to your query, you don't need to add it to the table. You can filter negative numbers in the where clause, or replace them by zero using CASE.
Hope this helps,
Pablo.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900