Saturday, 27 January 2018

php - Update field with result of DateDiff of two other populated fields




All I need to do is take two datetime fields and set a third field to its result.



This has to be easy but I've been working on it for 2 days and cannot get the result I'm looking for.



$con = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME) or die('Connection failed: ' . mysqli_connect_error());

$helpme=mysqli_query($con, "UPDATE chat_main SET Exact_Time = DATEDIFF(Start_TimeStamp, End_TimeStamp)");

mysqli_close($con);


Answer



The issue is that DATEDIFF returns the number of days between two dates. It appears that in the context of your implementation, the two dates are on the same day. So, you always get 0 as a result of DATEDIFF. I suggest using TIMEDIFF, which will be the difference of the two times, not the two dates.


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...