Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8113531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:51:31+00:00 2026-06-06T02:51:31+00:00

I’ve got 2 fields to populate: how many times the page is called per

  • 0

I’ve got 2 fields to populate: how many times the page is called per 15 minutes and per hour.

Following fields are DateTime in MySql:

$lastAccess15m=$row['lastAccess15m'];
$lastAccessHour=$row['lastAccessHour'];

And these fields are ints:

$accessPer15m=$row['accessPer15m'];
$accessPerHour=$row['accessPerHour'];

I want to compare current time with $lastAccess15, and if the time distance is larger than 15 minutes, set the value of $lastAccess15 to current time, and reset $accessPer15m, otherwise, increment $accessPer15m. The same goes for $lastAccessHour and $accessPerHour, after which those values have to be saved to mysql database.

How do I get the timespan between current time and $accessPer15m in minutes/hours?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:51:32+00:00Added an answer on June 6, 2026 at 2:51 am

    PHP time():

    Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

    MySQL datetime:

    The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in ‘YYYY-MM-DD HH:MM:SS’ format. The supported range is ‘1000-01-01 00:00:00’ to ‘9999-12-31 23:59:59’.

    To compare both of them, you need to convert one and them perform the comparison:

    $phpDateFromMysql = strtotime( $mysqldate );
    
    $mySqlDateFromPHP = date('Y-m-d H:i:s', $phpdate);
    

    The easiest way is to convert the Mysql value to time() and perform the comparison:

    See this working Example!

    <?php
    
    // compare if the value from $lastAccess15 is +15min in relation to the current time
    $lastAccess15 = '2012-06-01 00:00:00';
    
    $phpDateFromMysql = strtotime( $lastAccess15 );
    
    if ($phpDateFromMysql - $lastAccess15 > 900) {
        $lastAccess15 = date('Y-m-d H:i:s', time());
    }
    
    echo $lastAccess15;
    ?>
    

    Note: Inside the if statement you can perform the remaining of your operations, and even add an else clause to perform some operations if the time isn’t > 15min (like the increment you where referring to).


    Relevant reading material:

    PHP strtotime function

    PHP date function

    PHP elseif/else if control structure

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.