Time field - calculate time

  • sarah0173
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 8
  • Thank you received: 0

sarah0173 created the topic: Time field - calculate time

Hello everyone ! I need some assistance... And sorry for my english...
So, i have a form with 2 text fields that i use like "time" field (format HH:MM). And i need to make the calculation : time field 1 - time field 2 ; to get the duration.
Is there any way to do it ?
At first, i used 2 select lists for the time, but when i export the xsl file (i need that function), the hours are in 1 column, and the minutes in another one. So i've changed in text field with the time format validation.

Thank you for your help !
#225453
  • Posts: 2222
  • Karma: 44
  • Thank you received: 279

marko.bosnjak replied the topic: Time field - calculate time

Hello,

find the example attached.
When you install the form, you'll find 3 textfields: "start", "end" and "difference".

In the "start" element > Advanced tab > Actionscript > Type > Custom > Actions > Change you'll find this code:
function ff_start_action(element, action)
{
ff_difference_action(element, action);
}
In the "end" element > Advanced tab > Actionscript > Type > Custom > Actions > Change you'll find this code:
function ff_end_action(element, action)
{
ff_difference_action(element, action);
}
Both of those scripts are used for proceeding values to the "difference" element, where the calculation will be made.
In the "difference" element > Advanced tab > Actionscript > Type > Custom > Actions > Change you'll find this code:
function ff_difference_action(element, action)
{
var start = ff_getElementByName('start').value;
var end = ff_getElementByName('end').value;

var s1 = start.substr(0, 2);
var e1 = end.substr(0, 2);
var res1 = e1 - s1;

if (res1 > 0) {
var startDate = new Date("January 1, 1970 " + start);
var endDate = new Date("January 1, 1970 " + end);
var difference = Math.abs(startDate - endDate);

var hh = Math.floor(difference / 1000 / 60 / 60);
if(hh < 10) {
    hh = '0' + hh;
}
difference -= hh * 1000 * 60 * 60;
var mm = Math.floor(difference / 1000 / 60);
if(mm < 10) {
    mm = '0' + mm;
}
difference -= mm * 1000 * 60;

ff_getElementByName('difference').value = hh + ":" + mm;
}
else {
ff_getElementByName('difference').value = "The end value must be higher than start value!";
}
}
IMPORTANT: Inserted values must have the following syntax "hh:mm". If users add seconds or change the syntax in any other way, the script probably won't work correctly.

Try it out and let me know if you need any modification.

Regards,
Marko

======================================
Support Crosstec and get ALL EXTENSIONS and professional support for just $5
Here!
======================================
Need to renew Pro Support?
Buy Here!
======================================
Satisfied?
Consider a Membership!
======================================
Follow us on Facebook!
#225491
Attachments:
The following user(s) said Thank You: sarah0173
  • sarah0173
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 8
  • Thank you received: 0

sarah0173 replied the topic: Time field - calculate time

Thank you for your fast reply :) I'll try this weekend then i'll come back to you !!
#225543
  • sarah0173
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 8
  • Thank you received: 0

sarah0173 replied the topic: Time field - calculate time

It works like a charm ! A huge thank you !!!
#225547
  • Posts: 2222
  • Karma: 44
  • Thank you received: 279

marko.bosnjak replied the topic: Time field - calculate time

Awesome. :woohoo:
Let us know if you have more questions.

Regards,
Marko

======================================
Support Crosstec and get ALL EXTENSIONS and professional support for just $5
Here!
======================================
Need to renew Pro Support?
Buy Here!
======================================
Satisfied?
Consider a Membership!
======================================
Follow us on Facebook!
#225581
  • sarah0173
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 8
  • Thank you received: 0

sarah0173 replied the topic: Time field - calculate time

in fact i have a little issue...
When i put 10:05 in time field 1 and 10:45 in time field 2 i have this message "The end value must be higher than start value!" and the calcultation doesn't work... I don't understand why because the time field 2 is higher than the time field 1...

Thank you for your help !
#225773
Moderators: ForumSupporttomeperica
Time to create page: 0.099 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here