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

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
Highlighted
Power Apps
Power Apps

Re: Now() value in UTC?

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

Highlighted
Community Support
Community Support

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.
Highlighted
Helper I
Helper I

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

 

Highlighted
Resident Rockstar
Resident Rockstar

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
Check this Out

Announcing

Class of 2020- Season 2

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (8,265)