# Display type \_time

**URL:** <https://www.five.org/t/display-type-time/513>\
**Category:** How do I?\
**Created:** [February 6, 2025, 2:14pm UTC](https://www.five.org/t/display-type-time/513 "2025-02-06T14:14:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![CloudFuchs](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/cloudfuchs/32/961_2.png) [@CloudFuchs](https://www.five.org/u/CloudFuchs)\
**Post date:** [February 6, 2025, 2:14pm UTC](https://www.five.org/t/display-type-time/513/1 "2025-02-06T14:14:12Z")

</div>

We use the display type \_time

Is it possible to type in the time (hour and minute) directly to this field?

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/2X/8/88b9a153fccd769e55c56da65f6e0b05f8227a3e.png)

---

<div class="post-metadata">

**Author:** ![CloudFuchs](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/cloudfuchs/32/961_2.png) [@CloudFuchs](https://www.five.org/u/CloudFuchs)\
**Post date:** [February 6, 2025, 2:14pm UTC](https://www.five.org/t/display-type-time/513/2 "2025-02-06T14:14:46Z")

</div>

and can this be change to an 24 hour time view?

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/2X/a/aff807e29117a1eacc9954666610030eb5b168ec.png)

---

<div class="post-metadata">

**Author:** ![Vin-five.co](https://avatars.discourse-cdn.com/v4/letter/v/e480ec/32.png) [@Vin-five.co](https://www.five.org/u/Vin-five.co)\
**Post date:** [February 7, 2025, 1:17am UTC](https://www.five.org/t/display-type-time/513/3 "2025-02-07T01:17:45Z")

</div>

**Manual Time Entry:**  
Unfortunately, it’s not currently feasible to directly type the time (hour and minute) into this field.

**24-hour Format:**  
The 24-hour time view isn’t ready yet, but it will be considered for future updates.

---

<div class="post-metadata">

**Author:** ![JeanXXIV](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/jeanxxiv/32/548_2.png) [@JeanXXIV](https://www.five.org/u/JeanXXIV)\
**Post date:** [February 7, 2025, 2:23am UTC](https://www.five.org/t/display-type-time/513/4 "2025-02-07T02:23:14Z")

</div>

Hi CloudFuchs, I think I have the same use case. See this animated gift.

![input-time](https://canada1.discourse-cdn.com/flex030/uploads/five/original/2X/5/59ab79681da0436b1bc3c06bc8895f555cefab98.gif)

The fields in the database are of datatype “Time”. Is this what you want to do?

---

<div class="post-metadata">

**Author:** ![CloudFuchs](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/cloudfuchs/32/961_2.png) [@CloudFuchs](https://www.five.org/u/CloudFuchs)\
**Post date:** [February 7, 2025, 5:04am UTC](https://www.five.org/t/display-type-time/513/5 "2025-02-07T05:04:25Z")

</div>

hey, this is exactly what I need. How did you manag that?

Thank you,

Fabian

---

<div class="post-metadata">

**Author:** ![JeanXXIV](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/jeanxxiv/32/548_2.png) [@JeanXXIV](https://www.five.org/u/JeanXXIV)\
**Post date:** [February 7, 2025, 3:39pm UTC](https://www.five.org/t/display-type-time/513/6 "2025-02-07T15:39:04Z")

</div>

1- I made a custom display type (Setup \> Display types) with Display Type: Text and Mask: 99.99

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/2X/8/8d96fdd37802104021f02e839445c7bfb4c25d71.png)

2- In the form, set the display type of your time field to the custom type

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/2X/d/d9123bb8ab6fd98e457a66f8bcad9df1b1f2eea6.png)

3- In the same form field, call a function on the event ‘On Validate’

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/2X/b/bcf4bc43eed877faaeec870b8d3214fd0e918d04.png)

Here is the function for the startTime field. It is similar for the endTime field.  
This validates the time format, displays the time difference and ensures that startTime \< endTime.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/2X/5/5176a26782363597cd64233db94a8f6b5515aada.png)

In the next message, I will send the accessoiries functions stored in the libraries.  
Don’t forget to add the libraries functions in the Libraires tab of your function.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/2X/8/86b450ac33e3a60332bdc2795b4d089d6e2ccca9.png)

---

<div class="post-metadata">

**Author:** ![JeanXXIV](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/jeanxxiv/32/548_2.png) [@JeanXXIV](https://www.five.org/u/JeanXXIV)\
**Post date:** [February 7, 2025, 3:52pm UTC](https://www.five.org/t/display-type-time/513/7 "2025-02-07T15:52:01Z")

</div>

Here are the accessories functions, maybe the Five Team can optimize my solution. Hope this help!  
Jean

```auto
====================================================================
function formatTime(inputTime)
{
  const rawHours = inputTime.substring(0, 2);
  const rawMinutes = inputTime.substring(3, 5);

  const hoursWithoutSpace = removeSpaces(rawHours);
  const minutesWithoutSpace = removeSpaces(rawMinutes);

  if(isEmpty(hoursWithoutSpace))
  {
    throw new Error('Doit contenir l\'heure.');
  }

  if(isEmpty(minutesWithoutSpace))
  {
    throw new Error('Doit contenir les minutes.');
  }

  const hours = adjustLengthToTwoChars(hoursWithoutSpace);
  const minutes = adjustLengthToTwoChars(minutesWithoutSpace);

  if(parseInt(hours) > 23)
  {
    throw new Error('L\'heure doit être plus petite que 24.');
  }
  if(parseInt(minutes) > 59)
  {
    throw new Error('Les minutes doivent être plus petites que 60.');
  }
     
  return hours + ':'+ minutes + ":00";
}

function adjustLengthToTwoChars(chaine)
{
  if (chaine.length === 1)
  {
    return '0' + chaine;  
  }
  return chaine;
}

function removeSpaces(chaine) {
    return chaine.replace(/\s/g, '');
}
====================================================================
function getPositiveTimeDifference(begin, end) {

if ( !isEmpty(begin) && !isEmpty(end)) {

    const beginInSecond = mySqlTimeToSeconds(begin);
    const endInSecond = mySqlTimeToSeconds(end);
    const diff = endInSecond-beginInSecond;

      if(diff <= 0)
      {
         throw new Error("L\'heure de fin doit être supérieure à l\'heure du début.");
      }

    return secondsToHHMM(diff);
  }
  return 0;
}
====================================================================
function isEmpty(string) {
    return (string.length === 0);
}
====================================================================
function mySqlTimeToSeconds(time) {
    const [hours, minutes, seconds] = time.split(":").map(Number); // Sépare les parties et convertit en nombres
    return hours * 3600 + minutes * 60 + (seconds || 0); // Calcule le total en secondes
}
====================================================================
function secondsToHHMM(seconds) {

    const totalMinutes = Math.floor(seconds / 60);
    const hours = Math.floor(totalMinutes / 60);
    const minutes = totalMinutes % 60;
    return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
}
====================================================================

```

---

<div class="post-metadata">

**Author:** ![CloudFuchs](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/cloudfuchs/32/961_2.png) [@CloudFuchs](https://www.five.org/u/CloudFuchs)\
**Post date:** [March 3, 2025, 8:06pm UTC](https://www.five.org/t/display-type-time/513/8 "2025-03-03T20:06:27Z")

</div>

Thank you very much for your help!!!

I just needed another way to get a 24h time in the form, so I just used Regex for the validation:  
([01]?[0-9]|2[0-3]):[0-5][0-9]

the difference between start and end and will try to get it in the report only.
