cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper IV
Helper IV

Set the midnight time as per the user timezone

Hi, I am capturing the midnight time from my server(which is my D365 instance) to display in the app. There is a custom logic written on my d365 end which stops a timer function exactly at midnight based on the server time (GMT).  I am in India Timezone, so the timer stops exactly at 5:29:59(server time) which is 23:59:59(India time).  Now since this is a global app, I would like to stop the time based on user's locale midnight time.  Is there a way to find  the user timezone and then stop the timer exactly at his midnight and not server midnight time.  

Below Function displays the Start and end time. 

 

If(ThisItem.Running = 0, Text(ThisItem.StartDateTime, "[$-en-US]mmm dd yyyy hh:mm:ss") & " - " & Text(ThisItem.EndDateTime, "[$-en-US]mmm dd yyyy hh:mm:ss"),
 Text(ThisItem.StartDateTime, "[$-en-US]mmm dd yyyy hh:mm:ss") & " - " & "Running")

 

 

In the attached image, it shows that the timer started at 20:06:18 and stopped at 05:29:59 [Time is in India timezone].

What I would like to see is the end time as midnight time as per user timezone. 


timerimage.png

Thanks in advance

5 REPLIES 5
Super User III
Super User III

Hi @P_SA ,

You need the TimeZoneOffset function, which returns the user's difference to UTC.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hi, could you help me with the function. I am not sure how the offset works

Thanks @P_SA ,

Firstly, the TimeZoneOffset() returns the number of minutes the user's time zone is behind UTC as a positive value (a bit counter-intuitive when you first see it). My example (in Australian Eastern Time) for TimeZoneOffset(Now()) is -600, meaning I am 10 hours ahead of UTC. So you simply need to end the timer (say in India) 330 minutes (5.5 hours) before midnight or 6:30PM. The 330 will be -330 if someone in India used TimeZoneOffset(Now()) so the function will give you this value.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

 

Hi @P_SA ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Community Support
Community Support

Hi @P_SA ,

Based on the needs that you mentioned, I think the TimeZoneOffset() function could achieve your needs. The TimeZoneOffset function is used to the number of minutes between the user's local time and UTC (Coordinated Universal Time).

 

TimeZoneOffset() value = UTC (Coordinated Universal Time) - User's Local Time value

 

 

On my side, the TimeZoneOffset function result returns -480 (negative value), it means I am is (UTC + 8 ) Time Zone. If the TimeZoneOffset() function result is 480 (positive value), it means it is in (UTC - 8 )Time Zone.

 

If you want to convert your local time value into a UTC Time value, I think the combination of DateAdd function and TimeZoneOffset function could achieve your needs. Please take a try with the following workaround:

 

DateAdd(Now(), TimeZoneOffset(), Minutes)

 

On your side, you may need to type the following formula:

 

If(
   ThisItem.Running = 0, 
   Text(
        DateAdd(ThisItem.StartDateTime, TimeZoneOffset(), Minutes), "[$-en-US]mmm dd yyyy hh:mm:ss") & " - " & Text(ThisItem.EndDateTime, "[$-en-US]mmm dd yyyy hh:mm:ss"
   ),
  Text(ThisItem.StartDateTime, "[$-en-US]mmm dd yyyy hh:mm:ss") & " - " & "Running"
)

 

Please check the following article for more details:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-dateadd-datediff

If you want to convert UTC time value to local Time value, please modify above formula as below:

 

DateAdd(Now(), -TimeZoneOffset(), Minutes)

 

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (49,003)