Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Folks....

I have two SQL DateDiff() Queries like below..

SELECT DATEDIFF(MONTH,'07/01/2017','08/10/2017')

SELECT DATEDIFF(MONTH,'08/10/2017','07/01/2017')

Can anyone please help me which one i need to use?

Thanks in Advance..

What I have tried:

I am confused about '08/10/2017','07/01/2017' dates about which one i need to use start date and end date.
Posted
Updated 31-Jul-17 0:08am

Read the documentation : SQL Server DATEDIFF() Function[^]
 
Share this answer
 
As shown in the documentation, the function signature is
SQL
DATEDIFF(datepart,startdate,enddate)

then use
SQL
SELECT DATEDIFF(MONTH,'07/01/2017','08/10/2017')
if you need a positive number as return value.
 
Share this answer
 
v2
Comments
Member 11931581 31-Jul-17 6:17am    
Hi Pallini , i want a negative value ..Is it ok if i use like SELECT DATEDIFF(MONTH,'08/10/2017','07/01/2017') ?
CPallini 31-Jul-17 6:27am    
Yes, as you might see in the documentation.

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