Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Philword's avatar

Show number depending on date

I need help to understand what way to use to make function work depending on current day.

$dateOne = 2018-01-24

$dateTwo = 2018-07-24

$full_amount= 10000

$amountOne = 2500

$amountTwo = 416

$frequency = 2(months)

What I have now:

if (date("Y-m-d") >= $dateTwo) { 
        return $amountOne + $amountTwo;
    } elseif (date("Y-m-d") >= $dateOne) { 
        return $amountOne;
    } else {
        return 0;
    }

When current date >= $dateTwo I need to return $amountOne + $amountTwo but every 2 months ($frequency) after $dateTwo it need to sum plus one more $amountTwo or if it like 4 months ($frequency x 2) plus $amountTwo 2 times ($amountOne + amountTwo + amountTwo) etc.

In actual my users have some amount that they receive during some exact period partially. (you will have 10000 at all, but we will give it to you like $amountTwo parts every $frequency months until you get full amount (10000) )

if current date >= $dateOne + $frequency he will receive $amountOne + $amountTwo + $amountTwo. And it should work on what exact day today.

Hope I explained well, bc it can look a bit complicated to understand.

0 likes
0 replies

Please or to participate in this conversation.