Click here to Skip to main content
15,921,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear,

C#
How to get number of days in between two dates


I tried below query in SQL.

SQL
select DATEDIFF(DAY,'2016-03-11  12:00','2016-03-13  20:00')


its right but i want in decimal format.

Thanks
Basit

What I have tried:

select DATEDIFF(DAY,'2016-03-11 12:00','2016-03-13 20:00')
Posted
Updated 14-Mar-16 1:15am

1 solution

There is no SQL function for returning the difference in terms of days.hours or days.minutes - just for whole days, whole hours, and whole minutes.
If you want that, then you're going to have to create it yourself, and probably get the days, convert to hours, subtract that from the total hours, then take the days again, convert that to a float, convert the hours left to a float and divide it by an appropriate value (100 or 24, depending) before adding it on.
Nasty. If I needed it, I'd create an SQL function to do it, but I'd try and find a better way to handle my data first.
 
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