Forum


Calc Builder Support

Calc Builder support
Forums
Public write access is disabled. Please login

Add day 31.03.2017 12:47

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


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

Thanks

Re: Add day 31.03.2017 13:49

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


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

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

'm/d/Y'

in case you use the 4 digits format.

Hope this helps, regards
Moonsoft Team
www.moonsoft.es

Re: Add day 31.03.2017 14:24

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:

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

Re: Add day 31.03.2017 16:37

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

30/01/2017

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

d/m/Y

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.

Regards
Moonsoft Team
www.moonsoft.es

Re: Add day 02.04.2017 18:15

Thanks, It is work.
You are perfect.
Are you satisfied with our products/services/support?
Please help us to keep improving, add a review at  joomla extensions site and  magento connect
FaLang translation system by Faboba

Our clients' feedback