user11075777
user11075777

Reputation:

How do I subtract 2 timestamp from a dabase using php

For example, I have 2 dates

$start = 2020-08-15 20:39:43;
$end = 2020-08-15 20:59:43;

$total = $end - $start = 10 min;

how can I do that?

Upvotes: 0

Views: 40

Answers (1)

GMB
GMB

Reputation: 222462

Use timestampdiff():

select timestampdiff(
    minute,
    '2020-08-15 20:39:43',
    '2020-08-15 20:59:43'
)

If your dates are in columns start_ts and end_ts of table mytable, then:

select timestampdiff(minute, start_ts, end_ts) diff_minutes
from mytable 

Upvotes: 2

Related Questions