cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Szabolcs
Level: Powered On

Now() value in UTC?

Hi,

 

I need the current time in UTC, but the Now() function returns the value in local time.

How can I get it in UTC or how can I convert it from local to UTC?

 

Thanks,

Szabolcs

4 REPLIES 4
PowerApps Staff murali
PowerApps Staff

Re: Now() value in UTC?

You could do Text(Now(), DateTimeFormat.UTC)

Community Support Team
Community Support Team

Re: Now() value in UTC?

Hi Szabolcs,

 

For more details about Text function, please see this article below:
https://powerapps.microsoft.com/en-us/tutorials/function-text/

Best regards,
Mabel Mao

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Szabolcs
Level: Powered On

Re: Now() value in UTC?

Hi there,

 

Thanks for the answers, but my problem is a little different. Sorry for my short question. I try to explain the problem in more details.

 

I have an SQL database table with a datetime field. There is a button on my PowerApps form. When the user press the button I want to write the current timestamp to the database. Now my button's OnSelect is the following:

 

 

Patch('[dbo].[HS_ITDEVICESTABLE]';ThisItem;{APPROVALDATETIME: Now()})

Currently I am in CET timezone and after the Patch I see the local time in the database. But the database standard is to store the datetime values in UTC. So I need to convert the Now() to UTC somehow, but not as a text value, I need datetime value.

 

Another interesting thing that I see the datetime values on the PowerApps form converted from UTC to local. According to this I see a 1 hour different time comparing to the real button-press time.

 

An example:

1, I press the button at 10:00am local time

2, Patch function sends 10:00am to database

3, Database writes 10:00am to the table, which means 10:00am UTC

4, Database sends back the data to the app 10:00am UTC

5, App displays 10:00am UTC in local time, so I see on the form 11:00am

 

So, it looks that in write process there is no time conversion from local to UTC but in the show process there is a time conversion from UTC to local.

 

According to it I want to convert the Now() value "manually" from local to UTC before the Patch function.

 

Additional information: The database is an On-Premise SQL database of Dynamics AX 2012. I use On-Premise Data Gateway between SQL database and PowerApp.

 

Regards,

Szabolcs

 

KroonOfficeSol
Level 10

Re: Now() value in UTC?

For all who are looking for a solutions in this matter:

 

In the patch function use 

DateTimeValue(Text(Now(),DateTimeFormat.UTC))

What this does is writing the time as a UTC time (so UTC = Region Time). So in the database the actual time is stored.

 

To display the right Time you then have to convert the Region Time to UTC Time again

DateAdd(ThisItem.Time,TimeZoneOffset(ThisItem.Time),Minutes)

What happens is that you store a UTC Time which is equal to the Region Time. When you get this time back from the (sql) datebase this UTC time is converted to the region time and the DateAdd function adds or substracts the time in minutes between the region time and UTC Time. So the actual time (UTC) safed in the database is shown. 

 

Be aware that this workaround is not suitable when the time must change with different region, ' cause nine o'clock will be always nine o'clock. 

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

Users Online
Currently online: 184 members 5,113 guests
Please welcome our newest community members: