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

Convert 12-digit string to UTC date/time?

Hello all!

 

I'm writing a Flow that scrapes an API for data that includes a timestamp. If the timestamp is within the last 1 minute, the Flow should post a message as Flow bot to a Teams channel.

 

The challenge: the timestamp is a 12-digit string formatted yyyymmddhhmm. It's also in U.S. Eastern time. See screenshot below.

 

The Flow I've written below returns as a success in tests, but it doesn't post to the Teams channel as expected because the timestamp is greater than addMinutes condition always returns false, even though there is data in the API that should result in the condition returning true.

 

I'm pretty sure this is because the Flow is not reading the timestamp as a properly-formatted time and date in UTC. TBH, I didn't expect it to to test successfully at all — the fact that the condition is reading the string as a time and date at all is a surprise to me.

 

Because of that, I'm hoping the solution will just be that I need to convert the timestamp to the proper time. I'm hoping I don't have to use compose to separate and rebuild the timestamp.

 

Either way, I have no experience with converting time or compose. 

 

Any direction or guidance would be appreciated!

 

Screen Shot 2021-07-10 at 9.38.00 AM.pngScreen Shot 2021-07-10 at 9.39.34 AM.png

1 ACCEPTED SOLUTION

Accepted Solutions
ianhillmedia
Helper I
Helper I

Resolved, and a bit easier than I thought.

 

In the screenshot below...

 

Compose simply pulls the timestamp. I'm not sure why this step is needed, but without it, the Flow fails.

 

Compose 2 converts timestamp into a string:

string(outputs('Compose'))

 

Eastern then pulls timestamp into substrings, re-assembles them as yyyy-mm-dd hh:mm and formats that as time.

formatDateTime(concat(substring(outputs('Compose_2'),0,4),'-',substring(outputs('Compose_2'),4,2),'-',substring(outputs('Compose_2'),6,2),' ',substring(outputs('Compose_2'),8,2),':',substring(outputs('Compose_2'),10,2)),'yyyy-MM-dd hh:mm')

 

Convert to UTC, and it should work (it's not, but that's another post.)

 

Thanks for reading this as I worked through the issue!

Screen Shot 2021-07-10 at 4.18.27 PM.png

View solution in original post

3 REPLIES 3
ianhillmedia
Helper I
Helper I

Getting closer, but this is ugly.

 

Screen Shot 2021-07-10 at 2.56.45 PM.png

 

 

ianhillmedia
Helper I
Helper I

Resolved, and a bit easier than I thought.

 

In the screenshot below...

 

Compose simply pulls the timestamp. I'm not sure why this step is needed, but without it, the Flow fails.

 

Compose 2 converts timestamp into a string:

string(outputs('Compose'))

 

Eastern then pulls timestamp into substrings, re-assembles them as yyyy-mm-dd hh:mm and formats that as time.

formatDateTime(concat(substring(outputs('Compose_2'),0,4),'-',substring(outputs('Compose_2'),4,2),'-',substring(outputs('Compose_2'),6,2),' ',substring(outputs('Compose_2'),8,2),':',substring(outputs('Compose_2'),10,2)),'yyyy-MM-dd hh:mm')

 

Convert to UTC, and it should work (it's not, but that's another post.)

 

Thanks for reading this as I worked through the issue!

Screen Shot 2021-07-10 at 4.18.27 PM.png

Hi @ianhillmedia 

Glad that your issue is solved.

Thanks for your posting here and sharing the resolution in the forum as it would be helpful to anyone who encounters similar issues.

Best Regards

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (3,753)