Reputation: 81
Trying to get the time elapsed between two dates.
Say the start date is 01/01/2015 and the end date is 04/05/2015 - how could I express the time elapsed as 4 months, 3 days?
Using SSMS 2012.
Upvotes: 0
Views: 851
Reputation: 76
Since Muhammad already gave an answer for MYSQL and SQL server I will just add that if you are using Oracle you can simply subtract the dates:
TO_DATE('2015-01-01', 'YYYY-MM-DD') -
TO_DATE('2015-04-05', 'YYYY-MM-DD')
Upvotes: 1
Reputation: 158
The following tells you the difference between two dates in days, clearly you haven't told us your DBMS, so I posted two possibilities:
MySQL Syntax:
DATEDIFF(date1,date2)
DATEDIFF('2014-11-30','2014-11-29')
SQL Server Syntax:
DATEDIFF(datepart,startdate,enddate)
DATEDIFF(day,'2014-08-05','2014-06-05')
Links:
For MySQL, please visit: http://www.w3schools.com/sql/func_datediff_mysql.asp
For SQL Server, please visit: http://www.w3schools.com/sql/func_datediff.asp
Upvotes: 0