Skip to main content
Best answer

Convert minutes to hh:mm:ss with code

  • November 18, 2021
  • 5 replies
  • 1360 views

Hello,

 

I have a field coming from an app expressed in minutes and needs to format it into an hh:mm:ss format.

I could not find that option in date/time formatter so I’m trying with a Code by Zapier step.

I want a value such as 60 to become 01:00:00 or let’s say 90 would become 01:30:00, etc...

 

I have no preference for python or JS, whichever one works will do,

 

Looking forward to reading your ideas.

Cheers,

Thomas

Best answer by Troy TessaloneBest answer by Troy Tessalone

Hi @Thomas2M 

Try this JavaScript Code

 

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

5 replies

SamB
Community Manager
Forum|alt.badge.img+11
  • Community Manager
  • 7472 replies
  • November 18, 2021

Welcome to the Community, @Thomas2M!

I’m not 100% sure what code you’d need to use in order to convert the time into hh:mm:ss but it should be possible to select that format using a Formatter (Date / Time > Format) step.

As hh:mm:ss is a custom format you’d want to select the Custom value option and then type in the desired format directly into the To Format field. For example: 

e9cd2cd807c4fc65d5309eef45ef7809.png

You can find out more about using Formatter to adjust date/time formats here: Modify date and time formats in Zaps

Hope that helps! :)


  • Author
  • Beginner
  • 7 replies
  • November 19, 2021

Hi @SamB ,

 

How do you suggest I set the formatter date/time action for my particular requirement?

I tried a few options but no luck. The below set up returns “12:00:00” when I want 1:00:00 or 01:00:00

 

Let me know your thoughts.

 

Cheers


Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 30948 replies
  • Answer
  • November 19, 2021

Hi @Thomas2M 

Try this JavaScript Code

 


  • Author
  • Beginner
  • 7 replies
  • November 19, 2021

Hello @Troy Tessalone ,

 

Thank you for chiming in, your code works beautifully :relaxed:

 

Appreciate the help

 

Cheers


SamB
Community Manager
Forum|alt.badge.img+11
  • Community Manager
  • 7472 replies
  • November 19, 2021

Ah I see! Sorry for leading you down the wrong path there, @Thomas2M. You’re quite right, it does appear that it won’t do a straight conversion from minutes into hours. :(

I’m so glad you’ve since been able to get this sorted. Nice work here, @Troy Tessalone! :)