skip to Main Content

I need to get exit next date of payment of loan:

as loan date: 1-1-2020

loan period: 2 years 5 months

payment date: ? ?

calculating expected date of payment

// calculating next payment date
 date("Y-M-D", strtotime(date("2020-1-1")." + 2 years  + 2 months"))

2

Answers


  1. Try this,

    // Loan start date
    $loanStartDate = new DateTime("2020-01-01");
    
    // Loan period: 2 years and 5 months
    $loanPeriod = new DateInterval("P2Y5M");
    
    // Add the loan period to the loan start date
    $nextPaymentDate = clone $loanStartDate;
    $nextPaymentDate->add($loanPeriod);
    
    // Output the next payment date
    echo $nextPaymentDate->format("Y-m-d");
    

    IT will output the date that is 2 years and 5 months after January 1, 2020. In this case, it would output 2022-06-01.

    DateInterval Format Components

    P – Starts the period

    Date Components

    Y – Years (e.g., 2Y for 2 years)

    M – Months (e.g., 5M for 5 months)

    D – Days (e.g., 10D for 10 days)

    Login or Signup to reply.
  2. Try this, your code is correct and the date format is incorrect:

    date("Y-m-d", strtotime(date("2020-1-1")." + 2 years  + 2 months"))
    

    OR

    date("d-m-Y", strtotime(date("2020-1-1")." + 2 years  + 2 months"))
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search