Question : Need to change timezone for date times collected

Recently we where asked how to record the date and time in a survey but for the respondents time zone, not the time of the server.  The first question we asked was , are you asking where the respondent is, and they where so the answer was easy. Read on to see the full code and explanation.

The first thing we need to do is to find all the available times zones, in our example we are just going to do Perth and Sydney. If you search the DDL for timezones you will come across the list of them all under the “Time Zone Management”. Once we have the zone number we can create the metadata we need.

Metadata(en-AU, Question, label)
WhereAreYou "WhereAreYou" categorical [1]
    {
     _225 "Perth",
     _255 "Sydney"
    };
  �
 Message "The time in {place} is {thetime}" info;

End Metadata

Then all you need is the following routing ,

Routing(Web)
Dim oDateTimeNow,sNow

    WhereAreYou.ask()

    sNow = replace(ctext(format(WhereAreYou.response.value,"a")),"_"," ")
    oDateTimeNow = now(clong(sNow))

    message.Label.Inserts["place"].Text = format(WhereAreYou,"b")
    message.Label.Inserts["thetime"].Text =oDateTimeNow

    Message.ask()
End Routing

The first thing we do is to ask the WhereAreYou question and then get the category value. This done by using the format function on the response.value of the question asked and it will return {_255} if Sydney is chosen or {_225} if Perth is selected. We can the convert the value to a number by striping off the “_” and then converting it to a long with the CLONG function. Next we do the label inserts for the message  using the format function again to turn the name of the category rather than its value and the Finlay the new time is replaced into the message and displayed on the screen.

And this is what we end up with ,

Where are you
Where are you

 

and then ,

Show the answer
Show the answer

and there you have it a script that allows you to work out the time in a different timezone.

Leave a Comment

%d bloggers like this: