Forum


Calc Builder Support

Calc Builder support
Forums
No se permite escribir sin estar logado. Por favor, login

Count number of days 02.02.2016 17:33

I need some help in figuring out the formula for counting the number of days between 2 dates

Re: Count number of days 02.02.2016 17:58

Hi,
yes, we can provide that one. We assume you have created a couple of date fields at your form, please share which is the date format you're using (the one you've set at Preferences->front end date format) for your calculator.

Regards
Moonsoft Team
www.moonsoft.es

Re: Count number of days 02.02.2016 19:16

mm/dd/yy

Yes I have 2 date fields start date and end date

Edited by phil_adler - 02.02.2016 20:16

Re: Count number of days 03.02.2016 11:58

Hi,
ok, assuming your field dates variables are called 'startdate' and 'endddate', the code would be:

$format="m/d/Y";

$date1 = date_create_from_format($format,$startdate);
$date2 = date_create_from_format($format,$endddate);
$diff = date_diff($date1, $date2);

$days = $diff->d;

Now you have the difference at $days, that you can use for further calculations or print at the exit layout with ##days##

Please note those date functions above are valid starting from php 5.3, if you have an older version let us know so we'll provide another approach to get this result.
Please let us know if you need more help with this.
Regards
Moonsoft Team
www.moonsoft.es

Re: Count number of days 03.02.2016 16:10

perfect thank you very much. Now what would be the best way to add some css to it so it does not look like just some fields on a webpage

Re: Count number of days 03.02.2016 17:34

Hi,
you can enable bootstrap classes from the preferences tab, that will make the fields to adopt the bootstrap look and feel, otherwise they will be inheriting the styles from your template. If you want to add some more styles to the form, you can use the 'form layout' html editor, and also the js tab 'write directly in html page' if you want to include any external css file or style tag (this tab works including all its content inside the page)


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

Re: Count number of days 08.02.2016 17:10

I need to add 1 day to the calculation. I have used the $date2->modify('1 Day');

but the issue is I am adding a possible of 5 lines so when I add that code to each calculation the total returns 1 even if no dates are selected how do I fix this ?

Re: Count number of days 08.02.2016 17:25

Hi,
the reason is that you're adding one day to 'today'. If you don't want to show a result when any of the dates is empty, you can check this post regarding same question:



https://www.moonsoft.es/en/help/2/3299-inline-day-calculator

Regards
Moonsoft Team
www.moonsoft.es
Are you satisfied with our products/services/support?
Please help us to keep improving, add a review at  joomla extensions site and  magento connect

Lo que nuestros clientes opinan de nosotros