PHP sql Subtract two dateTime fields to a millisec

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neelsfer
    Contributor
    • Oct 2010
    • 547

    #1

    PHP sql Subtract two dateTime fields to a millisec

    I have two fields in a sql query for a html table that needs to be subtracted. The datetime format looks like this "19/08/2017 23:32:08.580"
    My sql with inner joins looks like this
    Code:
    $query = "SELECT tblentries.categories,tblracedetails.actual_start_time,tblentries.age,tblentries.firstname,tblentries.surname,tblentries.distance,tblentries.raceid,tblracetime.finishtime,tblracetime.raceno,tblentries.racedate,tblentries.racename,TIMEDIFF('tblracetime.finishtime','tblracedetails.actual_start_time') AS racetimes
    FROM tblentries
    INNER JOIN tblracetime
    ON tblentries.raceid = tblracetime.racesid AND tblentries.raceno = tblracetime.raceno
    INNER JOIN tblracedetails
    ON tblracedetails.id = tblentries.racesid AND tblracedetails.distance = tblentries.distance
    ";
    The data is stored in a varchar fields called "actual_start_t ime" and "finishtime ". The final subtracted format should be h:m:s:ms and the subtracted value must be called "racetimes" .
    The sql query above displayed, works 100% except for an empty 00:00:00 racetimes column.
    Any suggestions will be appreciated? Thx
Working...