0

I'm pretty new to Logic App so still learning my way around custom expressions. One thing I cannot seem to figure out is how to convert a FileTime value to a DateTime value.

FileTime value example: 133197984000000000

I don't have a desired output format as long as Logic App can understand that this is a DateTime value and can be able to run before/after date logic.

Paul
  • 227
  • 1
  • 3
  • 14
  • It looks like an epoch time but it's very long. Can you show us where it comes from? – Skin Feb 02 '23 at 21:30
  • This is actually coming from PowerShell's Get-Date to FileTime. In PowerShell you can recreate it using: `(Get-Date -Hour 0 -Minute 0 -Second 0 -Millisecond 0).ToFileTime()` This data is set in Active Directory so I am not able to change it. Unfortunately, I just have to work with the data that's given to me. :( – Paul Feb 03 '23 at 02:34
  • Oh cool, it'll be the .NET implementation then ... https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tofiletime?redirectedfrom=MSDN&view=net-7.0#System_DateTime_ToFileTime ... will look into and try and provide an answer. – Skin Feb 03 '23 at 03:32

2 Answers2

1

To achieve your requirement, I have converted the Windows file Time to Unix File Time then converted to File time by add them as seconds to a default date 1970-01-01T00:00:00Z. Here is the Official documentation that I followed. Below is the expression that worked for me.

addSeconds('1970-01-01T00:00:00Z', div(sub(133197984000000000,116444736000000000),10000000))

enter image description here

Results:

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
SwethaKandikonda
  • 7,513
  • 2
  • 4
  • 18
0

This isn't likely to float your boat but the Advanced Data Operations connector can do it for you.

The unfortunate piece of the puzzle is that (at this stage) it doesn't just work as is but be rest assured that this functionality is coming.

Meaning, you need to do some trickery if you want to use it to do what you want.

By this I mean, if you use the Xml to Json operation, you can use the built in functions that come with the conversion to do it for you.

This is an example of what I mean ...

Flow

  1. You can see that I have constructed some XML that is then passed into the Data parameter. That XML contains your Windows file time value.
  2. I have then setup the Map Object to then take that value and use the built in ado function FromWindowsFileTime to convert it to a date time value.
  3. The Primary Loop at Element is the XPath query that will make the selection to return the relevant values to loop over.

The result is this ...

Result

Disclaimer: I should point out, this is due to drop in preview sometime in the middle of Jan 2023.

They have another operation in development that will allow you to do this a lot easier but for now, this is your easier and cheapest option.

This kind of thing is also available in the Transform and Expert operations but that's the next tier level of pricing.

Skin
  • 9,085
  • 2
  • 13
  • 29