Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript decimal time to HH:MM

Guest
Jul 04, 2020 Jul 04, 2020

Hello

Need help with script, changing decimal time field to hours and minutes . Thanks 

 

TOPICS
PDF forms
2.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 05, 2020 Jul 05, 2020

What do you mean by "decimal time", exactly? Do you mean something like 1.5 should become 1:30?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 05, 2020 Jul 05, 2020

Hi 

Yes that is what I mean . What script could I use to change from decimal to hours and minutes. Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 05, 2020 Jul 05, 2020

You can use this code as the custom calculation script of the second field (adjust the name of the first one as needed):

 

var v = Number(this.getField("Text1").valueAsString);
var hours = Math.floor(v);
var minutes = (v-hours)*60;
var minutesString = (minutes<10) ? "0"+minutes : ""+minutes;
event.value = hours + ":" + minutesString;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 05, 2020 Jul 05, 2020

Thank you  . This worked perfectly

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 27, 2022 Oct 27, 2022

Hello, It's working but creating another decimal after minutes such as I need to convert 4.62 to minutes and results is 4:36.92 I wouldn't see .92 Would you help me please ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 28, 2022 Oct 28, 2022

Sorry, I don't follow what you mean... Do you want to display the result in a decimal value, instead of a time format (so 3.5 instead of 3:30)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 28, 2022 Oct 28, 2022

I want to display the result in a time hh:mm instead of a decimal value (so 3:30 instead of 3.5).

I have tried with your given script the result is 3:32.49 instead of 3.54. I need only 3:32 dont need extra 49 Please see the attached. 1.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 28, 2022 Oct 28, 2022
LATEST

The script I posted doesn't include seconds at all, only hours and minutes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines