Not calculating correctly
-
Hi there,
I have discovered an unusual error with this plug in.
I run a car parking business. I am using this plugin to calculate the number of parking days and the parking fees. This has been working well for the last 12 months.
But I have discovered an issue with the 7 Oct 2018. For example, if customer puts in the entry date as 7 Oct and exit date as 8 Oct then the calculator returns the number of days as 0. Seems to be an issue with this date.
Can you please look into this?
Thank you
HeathThe page I need help with: [log in to see the link]
-
Some further information –
1. Only seems to be an issue whenever the date range includes 7 Oct. Otherwise appears to work fine. Have not thoroughly tested.
2. Nothing has changed that I am aware of on my website – I have not updated any plugins on my website in more than a month.I have been able to troubleshoot this down to the value of date field. If I enter 6 Oct 2018 10:00 it returns 17810 (a whole number). If I enter 7 Oct 2018 10:00 it returns 17810.958333333332. For some reason it does not return a whole number as expected. This is causing the error that I am experiencing with the plugin.
Hope this helps diagnose the issue.
HeathHello
What browser are you using for testing, and which were exactly the values?
I’ve checked your form with Chrome, Firefox and Microsoft Edge, selecting: 07/10/2018 10:00 as the entry date, and 08/10/2018 10:00 as the exit date (like in your description) and it is working properly (the next screenshot was using Chrome as browser):

Please remember that the time participates in the equation, I’ve selected the same time in both date/time fields, if you modifies the time, the number of days can vary.
I insists, the form is working properly in every browser I’ve checked, for example, in this other case (the next screenshot was using Microsoft Edge as browser), I’ve modified the time in the exit date, where the result is more than one date, it would be one day and some hours:

The result is two days because you are using the CEIL operation to calculate the difference:
dateDiff = CEIL(fieldname4 – fieldname3);
By the way, please, remove the code you have entered in the onclick event of the calculate button because it is wrong, you have entered as the onclick event: fieldname1
and it is generating an uncaught error.Best regards.
Thanks heaps for your response.
And sorry forgot to say that I have modified my code to make it working better. The problem I reported originally has now been rectified. I am using Chrome.
We charge per 24 hour block and hence the ceiling calculation (e.g. 33 hours is 2 days).
I have removed the code on the calc button. Thanks
The issue I am now having is when I enter say:
Entry: 6 Oct 19:00
Exit: 7 Oct: 20:00The calculator works out it is 1 day, where as it should be 2 days. I think this is because of the date value issue I identified above. Can you please assist with this?
Thanks
HeathHello,
I’m sorry, but I’m testing the same form, using the Chrome browser, and the result entering the dates/times you are referring is 2 days, as should, please, look the screenshot:

I see you have disabled the dynamic evaluation of the equations, please, ensure to press the calculate button after modify the fields.
Best regards.
Thanks for the quick response. I am pressing calc after changing the fields.
Interesting as when I have put the entry and exit times below into chrome and also into safari on my phone and it is coming up with 1 day.
Entry: 6 Oct 19:00
Exit: 7 Oct: 20:00It is not working correctly for me.
I am using the following code for ‘Number of Days’:
(function(){
entry=CDATE(fieldname3, ‘yyyy-mm-dd hh:ii’);
exit=CDATE(fieldname4, ‘yyyy-mm-dd hh:ii’);dateDiff=ceil(fieldname4-fieldname3);
return dateDiff;
})();
debugging it
fieldname 3 (entry) value is 17810.458333333332
fieldname 4 (exit) value is 17811.416666666668dateDiff is therefore coming up with a value of 1. Whereas fieldname 4 – fieldname 3 should be more than 1, and hence the value of dateDiff should be 2.
Any ideas on what the issue is?
Thanks
Hello @driveparkfly,
I’ve tested your form from different browsers and devices, like IOS and Android and the form works properly in all of them please, look the screenshots below, and my suspictions at the end:
IOS – Safari

IOS – Chrome

Android – Chrome

My suspicts is that the issue is caused by your time-zone.
Could you indicate your time-zone to emulate it from my side, please?
Best regards.
Hello @driveparkfly,
I’m not sure if there is an issue with your browser’s cache of something, because I’ve modified even the timezone of my computer to emulate the different Australian time-zones, and your form continue working properly.
Best regards.
Thanks so much for your time on this. I am glad it is working for you. Yes I am in Australia AEST time zone.
I have tried it on a computer that has not opened the parking calculator webpage before and same result – it is coming up with 1 day when it should be 2.
A strange issue!
Hello @driveparkfly,
Only for testing, please, try the following modification:
Replace the piece of code:
dateDiff=ceil(fieldname4-fieldname3);"with the following one:
var diffObj = DATEDIFF(fieldname4,fieldname3, 'dd/mm/yyyy hh:ii', 'd'); dateDiff=diffObj['days']+IF(OR(diffObj['hours'],diffObj['minutes']), 1, 0);and let me know the result.
Best regards.Thanks for the test code.
I have created a new test page with this new code:
https://www.driveparkfly.com.au/calctest/Unfortunatley when I put in the same dates/times:
Entry: 6 Oct 19:00
Exit: 7 Oct: 20:00It is still not working correctly for me. Comes up with 1 day when it should be 2.
Hello @driveparkfly,
After many hours of testing I’ve identified the cause of error, you are using the Australian timezone, and in Australia the hour change the first Sunday of October at 2AM.
So, the October 6 at 19 hours would be:
Sat Oct 06 2018 19:00:00 GMT+1000 (Australian Eastern Standard Time)
and October 7 at 20 hours would be:
Sun Oct 07 2018 20:00:00 GMT+1100 (Australian Eastern Daylight Time)
Pay attention to the timezone in each case:
– GMT+1000 (Australian Eastern Standard Time)
– GMT+1100 (Australian Eastern Daylight Time)Actually, there are only 24 hours between both dates, and if you want the difference be considered as two days you should select at least the exit date as: October 7 at 20 hours and 1 minute (or 30 minute in your form)
Best regards.
Thank you so much! That makes perfect sense.
You are a champion.
Cheers
Heath
The topic ‘Not calculating correctly’ is closed to new replies.