Getting time to variable from time Input - Forum

Forum Navigation
You need to log in to create posts and topics.

Getting time to variable from time Input

Hi everyone,

I'm working on a project and need to capture the time from a Time Input element into a JavaScript variable in the format HH:MM
AM/PM. Can anyone advise on how to achieve this?

Thanks!

Uploaded files:
  • You need to login to have access to uploads.

@asmat

1) for the variable property of TimeInput1, change x to [x]

2) Now, when I select 1:07 AM, [x] is displayed as "1970-01-01T06:07:00.000Z" ... the date and time are separated by T

a) replace Z with nothing

b) replace double quotes with nothing

c)) parse the remaing text into an array using T as the separator ... the second array variable now contains 06:07:00.000

d) parse this into array using : as the separator ... the first two array variables are 06 and 07 ... let us call them [myHH] and [myMM] ... [myHH] is 5 more than i input because my local time (Toronto) is 5 hours behind UTC/GMT ... so add/subtract this amount to obtain the [myHH] in your locale.

e) if resulting [myHH] is greater than 12, subtract 12 from [myHH] and set [ampm] to "PM" ... else leave [myHH] as is and set [ampm] to "AM"

Your answer is [myHH]:[myMM] [ampm]

If I select 06:10 PM, applying logic 2 (a) to (e) above, [x] (displayed as "1970-01-01T23:10:00.000Z") will return 06:10 PM

 

Let me know if something is unclear or does not work.

luishp, Vadim and asmat have reacted to this post.
luishpVadimasmat
Hi @asmat,
take a look at the attached example.
where there is the following code in the change event of the time input.
If I understand the problem, I think this is enough.
TimeInputGetHour "[ora_input]" [h]
TimeInputGetMinute "[ora_input]" [m]

setvar [ampm] "AM"
Ifex ([h] == 12) 
   Setvar [ampm] "PM"
Endif
ifex ([h] > 12)
   math "[h]-12" 0 [h]
   setvar [ampm] "PM"
endif

setvar [h] "0[h]"
StrCopy "[h]" -2 2 [h]
setvar [m] "0[m]"
StrCopy "[m]" -2 2 [m]
setvar [ora] "[h]:[m] [ampm]"

 

Greetings Rocco


Uploaded files:
  • You need to login to have access to uploads.
luishp and asmat have reacted to this post.
luishpasmat

There is a small error in the app attached above, sorry. the code in the post is right

asmat has reacted to this post.
asmat