Hi folks,
Over the last few months, many of you have been asking for a Time field in Zoho Creator. We realize how important this field is to you all, and we promise to support this as soon as possible. In the meantime, here are a couple of workarounds that will help fetch the time from a Date-Time field.
1. Using the in-built
String functions
The easiest way to extract time for display purpose is to use a toString() function with preferred time format we need. We shall get the 24 hours format or 12 hours format in AM or PM for a given date time value.
24 hours format :
- zoho.currenttime.toString("HH:mm:ss"); //Sample Output : 15:30:30
12 hours format :
- zoho.currenttime.toString("hh:mm:ss a"); //Sample Output : 03:30:30 PM
Where zoho.currenttime is a system variable which returns the current date with time in the format set in application settings.
Note: Learn more about the syntax and usage of the substring function.
2. Using the in-built
Time and Date functions
Let's say you need to extract the time from the Date-Time field and display it in the following format -- 12Hour 34Minutes 40Seconds.
For which, you need to create a single line field and name it as 'Time' and then write the below-given code on On Load of the form.
Firstly, you need to fetch the current date and time using the zoho.currentime function and assign it to a variable called 'a'. Later, use the date and time functions to get the hour, minute and second values separately and assign them to three different variables.
- a = zoho.currenttime;
- b= a.getHour()+"Hour"+" ";
- c=a.getMinutes()+"Minutes"+" ";
- d=a.getSeconds()+”Seconds”;
- input.time=b+c+d; // Combine all the 3 three variables b,c, and d and assign it to the Time field.
Note: getHour(), getMinutes(), getSeconds() are the default in-built Date and Time functions. You can learn more about them here
.
If you have any doubts or queries regarding this tip, please feel free to add them as comments below. We would be happy to address them all.