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.
Time in PHP
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Time in PHP
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
(#10850)
Re: Time in PHP
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.
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.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Time in PHP
Then use the PHP DateTime and related classes: http://php.net/manual/en/book.datetime.php
(#10850)