Working datetime between php and mysql -


i'm want check if way correct or not. want calculate remaining time event.

there 3 component it.

  • the start datetime (in mysql datetime), retrieved mysql.
  • the duration (minutes in integer), retrieved mysql.
  • the current datetime, retrieved php function now().

to count:

  • the remaining time (in time hh:mm:ss), formula (start + duration) - now

my propose code is:

$row = data->fetch_assoc(); $start = $row["start_time"]; // e.g: "2015-06-19 09:37:16" $duration = $row["duration"]; // e.g: 60 (minutes) $now = time(); // e.g: 1434648994 $start_dt = strtotime ($start);  $remaining = ($start_dt + $duration * 60) - $now;  echo "remaining time: ".$remaining. " seconds." 

is correct?

your code calculates time until end of event.

and if $start_dt lower $now negative value.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -