Last updated 2 years ago
You possess a pair of columns labeled as "timestamp" and wish to determine the duration between their values? We will check in below example.
For solving this problem i have a table flight, in which we have arrival and departure time. See the below table.
flight
id | flight_name | flight_code | flight_arrival | flight_departure |
---|---|---|---|---|
1 | 6E2422 | 2023-05-02 05:29:51 | 2023-05-02 06:53:51 | |
2 | 9I696 | 2023-05-02 07:09:51 | 2023-05-02 08:53:51 | |
3 | AI404 | 2023-05-02 09:25:30 | 2023-05-02 09:56:30 | |
4 | AI812 | 2023-05-02 11:10:30 | 2023-05-02 11:56:30 |
SELECT id, flight_arrival, flight_departure, TIMESTAMPDIFF(SECOND, flight_arrival,flight_departure) AS standby_time FROM flight;
Output:
id | flight_arrival | flight_departure | standby_time |
---|---|---|---|
1 | 2023-05-02 05:29:51 | 2023-05-02 06:53:51 | 5040 |
2 | 2023-05-02 07:09:51 | 2023-05-02 08:53:51 | 6240 |
3 | 2023-05-02 09:25:30 | 2023-05-02 09:56:30 | 1860 |
4 | 2023-05-02 11:10:30 | 2023-05-02 11:56:30 | 2760 |
To compute the disparity among the timestamps within MySQL, employ the TIMESTAMPDIFF(start, end, unit) function. The unit parameter has several options such as MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.
The fact that people are spending more time on their phones makes now an excellent time to start a c...
Read ItCSS or Cascading Style Sheets have become a really popular programming language in recent times and...
Read It