Master Dev Master Dev - 1 month ago 7
MySQL Question

MYSQL get diffrence between two dattimes in minutes and update in field


  • I have table with 3 fileds id, startdate,enddate now i have added new field called mins as mentioned in image.

  • I need query to get diffrence between startdate and enddate in minutes and store in fields mysql...table image


Answer

Use MySQL TIMESTAMPDIFF() :

UPDATE YourTable t 
set t.mins =  TIMESTAMPDIFF(MINUTE,t.startdate,t.enddate) ;