Page 1 of 1
Time in PHP
Posted: Sat Jan 24, 2015 4:34 pm
by Hiver75
I'm trying to write PHP code that grabs a time from the database using PDO and then finds out how much time has past between it and the present.
How would you do that? Everytime I've tried it's given me errors.
Re: Time in PHP
Posted: Sat Jan 24, 2015 5:36 pm
by Christopher
You don't say what kind of database you are using, or what type of fields you are using. Databases have lots of functions for dates, such as DATEDIFF(), TIMESTAMPDIFF() or TIMEDIFF() ... MySQL:
http://dev.mysql.com/doc/refman/5.6/en/ ... tions.html
Re: Time in PHP
Posted: Sun Jan 25, 2015 9:22 am
by Hiver75
I'm using MySQL.
That seems to be a list of MySQL date commands, I can already grab the date from the DB fine enough, it's just when it comes to finding the difference between two dates in PHP, it doesn't work directly from the DB. All the other questions I've seen asked on this involve the date in plain text, not grabbing the date from the DB.
Re: Time in PHP
Posted: Sun Jan 25, 2015 12:47 pm
by Christopher
Then use the PHP DateTime and related classes:
http://php.net/manual/en/book.datetime.php