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

  • Home
  • SEARCH
  • 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 6147089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:03:10+00:00 2026-05-23T19:03:10+00:00

I am using a PHP variable that calculates the number of days between today

  • 0

I am using a PHP variable that calculates the number of days between today and when an entry was created:

DATEDIFF(NOW(), l.created)

How could I write a PHP equation where the first 30 days of this value are multiplied by 1 point each, then days 30-60 by 2 points each, then 60-90 by 3 points each, etc. up until the total number of days since creation, and then all points summed.

So if something has only been created for 15 days, it is then given 15 points. But if something has been created for 45 days, it is given 60 points (30 * 1 plus 15 * 2)?

  • 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-05-23T19:03:12+00:00Added an answer on May 23, 2026 at 7:03 pm

    Algorithm:

    $d = <number of days>;
    
    $m = intval($d / 30);  // completed months
    $r = intval($d % 30);  // remaining days beyond that
    
    $score = ($m * ($m + 1) / 2) * 30 + ($m + 1) * $r;
    
    //       ^^^^^^^^^^^^^^^^^^^        ^^^^^^^^
    //       accumulated levels        final lvl.
    

    Example: For $d = 45, we have $m = 1 and $r = 15, yielding 30 + 2*15 = 60.


    Here’s a free-standing formulation of this in SQL, but you have to hook it up to your function yourself with a subquery or a join or something:

    SELECT TRUNCATE((TRUNCATE(d/30, 0) * (TRUNCATE(d/30, 0) + 1) / 2) * 30 + (TRUNCATE(d/30, 0) + 1) * (d % 30), 0) AS score
    FROM (SELECT 45 AS d) AS t;   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP function that takes a variable number of arguments (using func_num_args()
I have a JavaScript variable that I echo out using PHP which is shown
How can I determine using PHP code that, for example, I have a variable
Using PHP, is there a function/method/way to check if a variable contains something that
So I'm doing some maintenance on a PHP site that is using $_SESSION variables.
Fairly simple issue which is solved in PHP by using a static variable. private
In php, I often need to map a variable using an array ... but
hello frieds this is how i usually post a variable using Jquery.. $.post(include/save_legatee.inc.php, {
I hava a php variable that contain JSON type data. $list = [{id:10,first_name:first,mi_name:,last_name:last,nick_name:HH}]; and
I am using arrays in PHP to modify xml data and write it back.

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.