Saturday, January 27, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...