cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
hjaf
Advocate V
Advocate V

read excel date _and_ time from a datetime column.

I have a table containing a column containing a date AND TIME serialized value (excel magic serialization (tm)).
I am able to get the date using something like addDays('1899-12-30', int(body('Get_row')?['DateAndTime'])). 

 

What is the most elegant and proper way to achieve this?

1 ACCEPTED SOLUTION

Accepted Solutions
yashag2255
Dual Super User II
Dual Super User II

Hi @hjaf 

 

I have this post here that explains in detail on how to work with date and time type columns of excel in Power Automate: 

https://www.bythedevs.com/post/working-with-date-time-data-of-excel-in-power-automate

 

Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

6 REPLIES 6
yashag2255
Dual Super User II
Dual Super User II

Hi @hjaf 

 

I have this post here that explains in detail on how to work with date and time type columns of excel in Power Automate: 

https://www.bythedevs.com/post/working-with-date-time-data-of-excel-in-power-automate

 

Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

I have tried something similar to this before. but i cannot fathom why i have to do something like this to extract a date from another element in the same ecosystem..


Right now I'm looking at converting the float from excel to a string, split it by '.' and int(first), add a "0." to the last to convert it back into a float and then do someting like:
addSeconds(adddays(<first>), mul(<last>, 86400)))

 

expressions like this feels so wrong.. this is crazy 

oneliner "solution" albeit not at all elegant:

addSeconds(addDays('1899-12-30', int(first(split(string('12345.6789'), '.')))), int(last(split(string(mul(float(concat('0.', last(split(string('12345.6789'), '.')))), 86400)),'.'))))

edit: added ludicrous oneliner expression

yashag2255
Dual Super User II
Dual Super User II

Hi @hjaf 

 

Yes. That is an issue actually with the excel connector. The date and time works in that manner for excel and so the workarounds that need to be used for handling that data via power automate. 

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Ok, so I eventually managed to get this working in a somewhat complicated context. reading multiple files and rows and columns. So it seems atleast. 

 

@yashag2255´s post was helpful, but I needed seconds as well

 

So for anyone ever having to work around this nightmare, here is my ridiculous solution step by step: 
Attention: this solution is not accurate on the second. This has probably to do with rounding done in excel and Power Automate. 
The example below is off with one second. I can perhaps work around this by ignoring decimals during the calculation, mod() or something like that. Suggestions appreciated. 

(this can be pasted into a compose for testing purposes)

Excel serialized time example:
@{string('43902.3547685185')}

Array([Date, Time])
@{split(string(mul(float(concat('0.', last(split(string('43902.3547685185'), '.')))), 86400)), '.')}

Seconds in day: 
@{first(split(string(mul(float(concat('0.', last(split(string('43902.3547685185'), '.')))), 86400)), '.'))}

Days since 1899-12-30:
@{int(first(split(string('43902.3547685185'), '.')))}

Date:
@{addDays('1899-12-30', int(first(split(string('43902.3547685185'), '.'))))}

Hours (today):
@{addSeconds(startOfDay(utcNow()), int(first(split(string(mul(float(concat('0.', last(split(string('43902.3547685185'), '.')) )), 86400)), '.'))))}

DateTime:
@{addSeconds(addDays('1899-12-30', int(first(split(string('43902.3547685185'), '.')))), int(first(split(string(mul(float(concat('0.', last(split(string('43902.3547685185'), '.')) )), 86400)), '.'))))}

DateTimeFormatting:
@{addSeconds(addDays('1899-12-30', int(first(split(string('43902.3547685185'), '.')))), int(first(split(string(mul(float(concat('0.', last(split(string('43902.3547685185'), '.')) )), 86400)), '.'))), 'R')}

DateTime formatting like SharePoint:
@{addSeconds(addDays('1899-12-30', int(first(split(string('43902.3547685185'), '.')))), int(first(split(string(mul(float(concat('0.', last(split(string('43902.3547685185'), '.')) )), 86400)), '.'))), 'yyyy-MM-ddThh:mm:ssZ')}

 Output:

Excel serialized time example:
43902.3547685185

Array([Date, Time])
["30651","9999984"]

Seconds in day: 
30651

Days since 1899-12-30:
43902

Date:
2020-03-12T00:00:00.0000000

Hours (today):
2020-04-13T08:30:51.0000000Z

DateTime:
2020-03-12T08:30:51.0000000

DateTimeFormatting:
Thu, 12 Mar 2020 08:30:51 GMT

DateTime formatting like SharePoint:
2020-03-12T08:30:51Z

 

Next challenge is getting a datetime back into a serialized excel datetime. I will add it here once i find a reliable way.

Hi @hjaf ,

 

I'm afraid that we couldn't get a accurate second time since the date time value we get from the excel table is a converted float.

 

Best Regards,

Alice

 

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

yes i think @yashag2255's solution is the way to go. i need to use ticks like he does to be accurate.

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Users online (2,701)