Home > database >  How to calculate month deadline in php [closed]
How to calculate month deadline in php [closed]

Time:09-29

I'm working on a system that allow the user to set the number of month for their own duration as the deadline for their project. The problem I'm facing now is how do I calculate their duration starting from the day they submitted their project to its deadline.

This is the input where the user can set their month duration:

<label>Duration:</label>
<input type="number" name="duration" placeholder="Number of months" required="">

This is what I wanted to do just to make it clear:

*Let's say the user set 9 month on duration input.

*And since today is september 2021 as I posted this problem. The start of the project will be this month, and the deadline will be on 2022 June.

I already searched something about this and I can't find the right solution or maybe I just don't know the right keyword to search for.

CodePudding user response:

If I understand you correclty you want to add X month to the current date.

You can do something like

$date = new DateTime('now');
$date->modify(' '. $x .   ' month'); //x is your input value

See https://www.php.net/manual/en/datetime.modify.php for more information.

CodePudding user response:

Please check this link, I have added the code snippet. https://code.sololearn.com/wj3KDnCq7rVJ/?ref=app

  • Related