Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query DateTime.FromFileTime: Convert File Time to DateTime

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The DateTime.FromFileTime function in Power Query converts a Windows file time (a 64-bit integer representing 100-nanosecond intervals since January 1, 1601 UTC) into a readable date and time value. This is essential when working with data from Windows system logs, Active Directory, or registry exports where timestamps are stored in this format. No external tools or installations are required—you only need access to Power Query in Excel, Power BI, or other supported platforms.

What You'll Need

  • Microsoft Excel 2016 or later, or Power BI Desktop
  • A column of numeric values representing Windows file times (typically 64-bit integers)
  • Access to Power Query Editor (available via Data > Get Data > From Table/Range in Excel or Transform Data in Power BI)

Step-by-Step

  1. Load your data into Power Query. In Excel, select your data range and choose Data > From Table/Range. In Power BI, select your table and click Transform Data. Ensure the column containing file time values is formatted as Whole Number or Decimal Number.
  2. In Power Query Editor, locate the column with the file time values. Right-click the column header and select Change Type > Int64 (if not already set). This ensures the data is treated as a 64-bit integer, which is required for DateTime.FromFileTime to work correctly.
  3. Click the Add Column tab in the ribbon, then select Custom Column from the group.
  4. In the Custom Column dialog box, enter a name for your new column—such as "ConvertedDateTime".
  5. In the Custom column formula box, type: DateTime.FromFileTime([YourColumnName]) where "YourColumnName" is the exact name of your file time column (e.g., [LastWriteTime]). Do not include quotes around the column name.
  6. Click OK. Power Query will process each row and generate a new column with converted date-time values formatted as yyyy-mm-dd hh:mm:ss.
  7. Verify the results by scrolling through the new column. Values should appear as human-readable dates (e.g., 2023-08-15 14:22:05). If you see errors, review the troubleshooting section.
  8. Click Close & Load (Excel) or Close & Apply (Power BI) to return the transformed data to your worksheet or data model.

Common Mistakes

  • Using DateTime.FromFileTime on text values instead of numbers. The function only accepts numeric input; if your column is formatted as text, it will return an error.
  • Typing the column name with quotes or brackets incorrectly. Use [ColumnName], not "ColumnName" or ["ColumnName"].
  • Using 32-bit integers instead of 64-bit. File times are 64-bit values; truncating them to 32 bits (e.g., by importing as Integer) will produce wildly incorrect dates.
  • Assuming local time conversion. DateTime.FromFileTime assumes the input is in UTC. If your source data is stored in local time, the result will be misaligned by your time zone offset.
  • Confusing it with DateTime.FromFileTimeUtc, which is not a valid function—DateTime.FromFileTime already returns UTC. There is no separate "Utc" variant.

Tips

  • Always validate a few converted values against known timestamps. For example, a file time of 133250000000000000 should convert to approximately 2020-06-15 12:13:20 UTC.
  • If you need to display the result in your local time zone, wrap the function in DateTimeZone.ToLocal: DateTimeZone.ToLocal(DateTime.FromFileTime([YourColumn])).
  • Use the Format column feature after conversion to adjust display format (e.g., "yyyy-MM-dd HH:mm:ss") without changing the underlying value.
  • When working with large datasets, test on a sample of 100 rows first to ensure accuracy before processing the full dataset.
  • If you’re pulling from Active Directory or registry exports, double-check how the file time was exported. Some tools may apply time zone offsets during export, requiring manual correction before conversion.

Troubleshooting

  • Error: "We cannot convert the value to type Number" — This means your column contains non-numeric data. Check for blank cells, text headers, or corrupted entries. Use Transform > Replace Values to remove unwanted text or filter out nulls before applying the function.
  • Result is a date in 1601 or 1700 — This indicates the file time value is 0 or very close to it. This is the epoch start date for Windows file time. Confirm your source data is not corrupted or missing. A value of 0 means no timestamp was recorded.
  • Result is years in the future (e.g., 2100+) — The input value is likely incorrect or truncated. Check if the number is being imported as a 32-bit integer. Re-import the data and explicitly set the column type to Int64 during data loading.
  • Function returns null — This occurs when the input is null or invalid. Add a conditional step: if [YourColumn] = null then null else DateTime.FromFileTime([YourColumn]).
  • Performance is slow on large datasets — DateTime.FromFileTime is computationally intensive. Consider filtering out rows with null or zero values before conversion to reduce processing load.

Frequently Asked Questions

Can DateTime.FromFileTime handle negative values?

No. Negative file times are not valid in Windows and will return an error. File times are always positive 64-bit integers representing dates after January 1, 1601 UTC.

What if my file time is stored as text?

Convert it to a number first. Use Transform > Data Type > Whole Number or use the Value.FromText function as a precursor: DateTime.FromFileTime(Value.FromText([ColumnName])).

Does this function work in Power Automate?

No. DateTime.FromFileTime is a Power Query function and is not available in Power Automate flows. Use equivalent expressions like addSeconds('1601-01-01T00:00:00Z', div(yourFileTime, 10000000)) in Power Automate.

Why is my converted time 5 hours off?

Your source file time may have been recorded in local time instead of UTC. The function assumes UTC input. To correct this, subtract your time zone offset before conversion, or use DateTimeZone.ToLocal after conversion if the source was UTC.

Can I convert back from DateTime to file time?

Yes, use DateTime.ToFileTime. For example: DateTime.ToFileTime(DateTime.FromFileTime([YourColumn])) will round-trip the value. This is useful for validation.

Do I need to restart Excel or Power BI after using this function?

No. Power Query functions apply instantly during data transformation. Only restart if you encounter persistent interface issues or after software updates.