## How to get difference between two dates in days and hours?

 Author Message Srikanth 21 SSC Journeyman Group: General Forum Members Points: 86 Visits: 275 Hi, I'm looking code to find difference between two dates in days and hours. Example:date1: 2013-04-07 14:45:41.013 - date2: 2013-04-05 10:45:41.013I need output like 2 days and 6 hours? bitbucket-25253 SSCertifiable Group: General Forum Members Points: 5687 Visits: 25280 Use the DATEDIFF functions ... for example SELECT DATEDIFF ( datepart , startdate , enddate )This will return the number of days difference.SELECT DATEDIFF(d,'2013-04-05 10:45:41.013','2013-04-07 14:45:41.013')returns 2 daysThis returns the total number of hours difference (52)SELECT DATEDIFF(hh,'2013-04-05 10:45:41.013','2013-04-07 14:45:41.013')--combining every thing I think will give you what you are looking for:`   SELECT DATEDIFF(hh,'2013-04-05 10:45:41.013','2013-04-07 14:45:41.013')/24 AS 'Days'       ,DATEDIFF(hh,'2013-04-05 10:45:41.013','2013-04-07 14:45:41.013') -        (DATEDIFF(hh,'2013-04-05 10:45:41.013','2013-04-07 14:45:41.013')/24)*24 AS 'Hours'Result:Days   Hours2   4 ` If everything seems to be going well, you have obviously overlooked something. RonPlease help us, help you -before posting a question please read Before posting a performance problem please read Srikanth 21 SSC Journeyman Group: General Forum Members Points: 86 Visits: 275 Thanks, It's worked.