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 7877163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:17:33+00:00 2026-06-03T03:17:33+00:00

function convertDates($timestamp) { return date(‘Y-m-d’, $timestamp); } $days = array(); //storing databases php time();

  • 0
function convertDates($timestamp) {
    return date('Y-m-d', $timestamp);
}
$days = array(); //storing databases php time();
$complete = array(); //storing the generated missing days
$occurrences = array(); //finding how many php time() are on same day
$zero = array(); //instead of storing occurrence as 1, store it as zero
$query = mysql_query("SELECT `login` FROM `statistics` ORDER BY `login` ASC");
while($rows = mysql_fetch_array($query)) {
    $days[] = $rows['login']; //filling array with times
}
$days[] = time(); //append current time
for($i = 0; $i < count($days); $i++) {
    $complete[] = convertDates($days[$i]);
    $difference = isset($days[$i+1]) ? $days[$i+1] - $days[$i] : 0;
    if($difference >= 86400) {
        $difference = ceil(abs($difference/86400));
        $fill = $days[$i];
        for($k = 0; $k < $difference; $k++) {
            $fill += 86400;
            $complete[] = convertDates($fill);
            $zero[] = convertDates($fill);
        }
    }
}
$occurrences = array_count_values($complete);
$complete = array_unique($complete);
$zero = array_unique($zero);
sort($complete);
echo "[";

for($i = 0; $i < count($zero); $i++) {
    echo "[\"".$zero[$i]."\",0], ";
}

for($i = 0; $i < count($occurrences); $i++) {
    if($i == count($occurrences)-1)
        echo "[\"".$complete[$i]."\",".$occurrences[$complete[$i]]."]";
    else {
        echo "[\"".$complete[$i]."\",".$occurrences[$complete[$i]]."], ";
    }
}
echo "]";

I’m plotting points into a jqplot graph and for the statistics I need to define days the user did not login. Lets call these “gaps”

The user logs in on March 25, 2012 and does not log back in for 5 days. It is now March 30, 2012. I have to generate those missing days from the two dates.

My current algorithm doesn’t seem to be working. I can’t figure out what is going wrong.

The dates in the database are from php time();

I stored all the values into an array $days

Here is the output from the logins table generated by the script. Note it is encoded for the jqplot:

[["2012-04-01",0], ["2012-04-02",0], ["2012-04-03",0], ["2012-04-04",0], ["2012-04-05",0], ["2012-04-07",0], ["2012-04-08",0], ["2012-04-09",0], ["2012-04-10",0], ["2012-04-11",0], ["2012-04-12",0], ["2012-04-13",0], ["2012-04-14",0], ["2012-04-15",0], ["2012-04-16",0], ["2012-04-17",0], ["2012-04-18",0], ["2012-04-19",0], ["2012-04-20",0], ["2012-04-21",0], ["2012-04-22",0], ["2012-04-23",0], ["2012-04-24",0], ["2012-04-25",0], ["2012-04-26",0], ["2012-04-27",0], ["2012-04-28",0], ["2012-04-29",0], ["2012-04-30",0], ["2012-03-31",1], ["2012-04-01",2], ["2012-04-02",2], ["2012-04-03",1], ["2012-04-04",19], ["2012-04-05",13], ["2012-04-06",8], ["2012-04-07",1], ["2012-04-08",1], ["2012-04-09",4], ["2012-04-10",1], ["2012-04-11",1], ["2012-04-12",2], ["2012-04-13",1], ["2012-04-14",1], ["2012-04-15",1], ["2012-04-16",2], ["2012-04-17",10], ["2012-04-18",1], ["2012-04-19",1], ["2012-04-20",1], ["2012-04-21",1], ["2012-04-22",1], ["2012-04-23",1], ["2012-04-24",1], ["2012-04-25",1], ["2012-04-26",1], ["2012-04-27",1], ["2012-04-28",1], ["2012-04-29",1], ["2012-04-30",2]]

My script is not working. How can I properly generate the days where the user did not login?

Thank you for your time.

  • 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-03T03:17:35+00:00Added an answer on June 3, 2026 at 3:17 am

    Use a loop to go through successive dates, using a function like:

    $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");
    

    For each cycle, apply your query result. Then you’ll have all the dates. You’ll still be using a loop; but the basis will be day progression, not your query result.

    Pseudo-code:

    for ($day_counter = 0; $day_counter < 365; $day_counter++) {
    
        $day_this = strtotime(date("Y-m-d", strtotime($day_this)) . " +1 day");
        $login_count = mysql_query("SELECT COUNT(DATE(login)) AS date_login 
                    FROM statistics 
                    WHERE date_login=".$day_this);
    
        array_push($days, array($day_this=>$login_count);
    
    }
    

    Not sure how this part should look:

    COUNT(DATE(login))  
    

    … but the idea is that you convert a date-time value to a simple date, then run a count.

    CORRECTION:

    COUNT(DATE(login)) is wrong. You must apply the COUNT() function to a distinct record field (usually a primary key), and use the function that collapses date/time into a simple date in the WHERE clause. I often start with what I wrote above and then figure this out. 🙂

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

Sidebar

Related Questions

<?php function convertDates($timestamp) { return date('Y-d-m', $timestamp); } $days = array(); //store all the
function returnsAnArray () { return array ('test'); } echo returnsAnArray ()[0]; generates a syntax
function getsession(){ var data = $.get('../session', function(data) { return data; }); return data; }
function Submit_click() { if (!bValidateFields()) return; } function bValidateFields() { /// <summary>Validation rules</summary> ///
function countChars(elm) { if (elm.nodeType == 3) { // TEXT_NODE return elm.nodeValue.length; } var
function myClass() { this.nums = [1,2,3]; this.divisor = 2; } myClass.prototype.divideNumsByDivisor = function(){ return
function strip_cdata($string) { preg_match_all('/<!\[cdata\[(.*?)\]\]>/is', $string, $matches); return str_replace($matches[0], $matches[1], $string); } I use the
function example(){ var quantity = http://www.example.com/index.php?brandid=b%123&quantity=20; quantity = quantity.replace(-what regular expression should i user-,
Function calculate_attribute does not return a value; it only works through side effects. Often
function ff_chk_username_unique(element, action) { alert(element.value); alert(action); var actiona=http://localhost/myproject/check/check_username.php; var form_data = { username: element.value,

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.