Hello, I am trying to run some queries but my output is not right. Could anyone please help me understand what I'm doing wrong? I am trying to find the difference between these two DATETIME values as minutes.
SELECT TO_CHAR(booking_StartTime - booking_EndTime) AS Diff FROM Booking;
CodePudding user response:
Assuming that booking_StartTime
and booking_EndTime
are DATE fields - when doing arithmetic using DATE values in Oracle the result is a number of DAYS. Thus, to get minutes you have to multiply by the number of minutes in a day, i.e. by 24 * 60, or 1440. Also - you probably want to subtract the start time from the end time, in order to get a positive value as the result.
SELECT TO_CHAR((booking_EndTime - booking_StartTime) * 1440) AS Diff FROM Booking;
should get you what you want.