CalcBuilder Forum

Add day

User mehmethocam1 2017-03-31 12:47:06

Frontend Date format is mm/dd/yy (variable baslangic)
I want to add to 40 day to my variable.
How can I?

// Not correct
$newDate = new JDate($baslangic .' +'.$dayf.' day');
$result= $newDate->format('m/d/Y');


Moonsoft support 2017-03-31 13:49:53

you can try to use php datetime class in order to perform your function, the code should look like:

//create date object from format
$newDate = DateTime::createFromFormat('m/d/y', $baslangic);
//add interval
$newDate->modify('+'.$dayf.' days');
//return formatted new date

That should do the work, format to be used here is 'm/d/y' if you use 2 digits for year, or,


in case you use the 4 digits format.

Hope this helps, regards

User mehmethocam1 2017-03-31 14:24:29

Thanks support.

Code produces incorrect results.

Sample baslangic is 01/01/2017
Result: 10/02/2017 This is correct

Sample baslangic is 30/01/2017
Result: 11/07/2019 This is not correct.

I can tired code:

//create date object from format
$newDate = DateTime::createFromFormat('m/d/Y', $baslangic);
//add interval
$newDate->modify('+'.$dayf.' days');
//return formatted new date

Moonsoft support 2017-03-31 16:37:32

are you sure the date format is the right one? You said you're using mm/dd/yy format, but from your example:


seems you're using dd/mm/yy instead? If so, you only need to correct the date format to


at the 2 date functions (createfromformat and format) in order to get the right results. If the format is not the exact one you'll be getting weird unexpected results when adding the days.


User mehmethocam1 2017-04-02 18:15:39

Thanks, It is work.
You are perfect.


Perfect for small code changes or to correct any bug at your site

Buy now!
Support/development 10 hours

Get a bigger amount of hours for more complex tasks and get a 10% discount

Buy now!