Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

A time equation...

Here is what my project calls for... I will need to compare a time (hour min sec) retrieved from the database to the current time and figure out if the new time is newer by five or more minutes as the start of an if statement. In other words, if the current time is five minutes later than the old time (from the server (mysql)) then....

I have played with mktime, but I get a string of numbers I am not sure what to do with.

1 Solution
// convert to a unix timestamp
$database_date = strtotime($database_date);

if (time() >= strtotime('+5 minutes', $database_date))
  // 5+ minutes have passed since the database date

Note that, since you're dealing with minutes (always the same length), you could also do:

if (time() >= ($database_date + (5 * 60)))

And save yourself a function call. The time interval is just a little more obfuscated that way.
cbonnockAuthor Commented:

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now