Smart Systems for Home

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

DateTime.Date in Power Query: How to Use It

· 7 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

DateTime.Date is the Power Query M function that takes a full date-and-time value and returns just the date part, with the time portion set to midnight. So DateTime.Date(#datetime(2025, 3, 14, 17, 45, 0)) returns 14 March 2025 with no time attached. It is the clean way to strip timestamps from a column before grouping, joining or filtering by day. Before you start, you need Power Query open (in Excel via Data > Get Data, or in Power BI via Transform data), and you need to know that Power Query is case-sensitive: DateTime.Date with full capitals is a different, working function from datetime.date typed in lower case, which will fail.

What You'll Need

  • Excel with Power Query (Data > Get Data > Launch Power Query Editor) or Power BI Desktop (Home > Transform data). The function exists in both; menu labels can differ slightly by version, device or region.
  • A table or query that already contains a Date/Time column. Power Query only shows the time part if the column's data type is Date/Time, not Text.
  • Access to the formula bar, or willingness to add a custom column, because DateTime.Date is an M function rather than a button in the ribbon.

Step-by-Step

  1. Load your data into Power Query. In Excel, select your table and go to Data > From Table/Range. In Power BI, use Home > Transform data to open the editor on an existing query. Make sure the timestamp column is present in the preview.
  2. Confirm the column's data type. Click the type icon at the left of the column header. If it shows ABC/123 (Text), the date function will not work on it. Change it to Date/Time first (choose Date/Time from the list). If the conversion produces errors, the source text is not in a format Power Query recognises, and you need to fix that before continuing.
  3. Add a custom column. On the Add Column tab, click Custom Column. Name it something like OrderDate (no spaces keeps later steps simple). In the formula box, type exactly: DateTime.Date([YourColumnName]) replacing [YourColumnName] with the real column name from the list on the right. Column references are case-sensitive in M, so click the column name in the available-columns pane rather than typing it.
  4. Check the result type. When you click OK, Power Query adds the new column. If the values look like 2025-03-14, you are done. If you see #date(2025, 3, 14) or a value with a 12:00:00 AM time attached, right-click the new column header and set the type to Date explicitly.
  5. Use it inline where a step needs a date. Many transformations accept a custom formula instead of a column. For example, Filter Rows > Date/Time Filters lets you choose is after or is before and type a date, but if you need a computed bound, use a custom filter formula such as [OrderDate] >= DateTime.Date(DateTime.LocalNow()) to keep only today's rows and later. This is how you build a rolling filter that excludes the time part of the comparison.
  6. Group or join by the date. Once you have a clean Date column, select it and use Home > Group By to sum or count per day, or use Home > Merge Queries to join to a calendar table on the date. Joins between a Date column and a Date/Time column often fail or double-match, so converting both sides with DateTime.Date is the reliable fix.
  7. Close and load. Click Home > Close & Load (Excel) or Home > Close & Apply (Power BI). The query refreshes on demand and the date-only column recalculates from the source.

Common Mistakes

  • Typing it in lower case. M is case-sensitive. datetime.date is not the function; DateTime.Date is. The same applies to DateTime.LocalNow, which is not datetime.localnow.
  • Passing a text value. If the column is typed as Text, DateTime.Date returns an error. Convert the column to Date/Time first, or wrap the text in DateTime.FromText before applying DateTime.Date.
  • Expecting a text result. DateTime.Date returns a date value, not a string. If you need the text "2025-03-14" for export, add Date.ToText around it with an explicit format, or you may get locale-specific output.
  • Square brackets in the wrong place. Inside a custom column, refer to fields as [OrderDate]; in a table-level step context you may need a row reference. Mixing them is the usual source of "The field was not found" errors.
  • Assuming it rounds. DateTime.Date truncates the time; it does not round to the nearest day. A timestamp of 23:59 on the 14th becomes the 14th, not the 15th.
  • Repeating the conversion on every refresh. If you add the step each time you edit, you accumulate duplicate columns. Check the Applied Steps pane and delete redundant ones.

Tips

  • Name the custom column simply and reuse it. Referencing an earlier step's column by name is much easier to debug than nesting functions.
  • Build a calendar table once with a dedicated date column and join on it; this simplifies reporting by month, quarter or weekday without repeated conversion.
  • Use Date.Year, Date.Month and Date.Day on the converted column to produce year, month number and day-of-month columns for sorting and grouping.
  • When comparing dates, compare Date to Date. Mixing Date and Date/Time values in comparisons gives results that look correct in the preview but shift after refresh.
  • Add a small test step with a fixed value, such as DateTime.Date(#datetime(2025, 1, 1, 9, 30, 0)), to confirm the function is available before wiring it into a large query.
  • Keep the original timestamp column alongside the new date column. You may need it later for time-of-day analysis, and deleting it is easy to regret.

Troubleshooting

If it did not work, start with the error message text. "The name 'datetime.date' is not recognised" means a case or spelling problem; correct it to DateTime.Date. "We cannot convert the value X to type Date" means the input column still holds text or an invalid date; change the column type first and look for the error rows. "The field 'YourColumnName' of the record was not found" means the column name is different in the current step, often because a previous step renamed it; click the actual column name in the available-columns list instead of typing it.

If the custom column is added but every value is null, the source column contains blanks. Power Query passes blanks through as null rather than raising an error, so inspect the source and filter out empty rows if needed. If the query is slow after adding the step, remember that the conversion is cheap but a filter placed after it may prevent query folding against the source; try moving the filter earlier if your source supports folding. If results change unexpectedly after a refresh, check for Date versus Date/Time mismatches and for locale settings affecting how the source text is parsed. And if a whole step breaks after you edited it, use the delete button next to the step in Applied Steps and rebuild it from the previous step rather than trying to repair it.

Frequently Asked Questions

What is the difference between DateTime.Date and Date.From?

DateTime.Date expects a Date/Time value and strips the time. Date.From is more flexible and accepts a date, number or text and converts it. Use DateTime.Date when you already have a timestamp column; use Date.From for looser conversions.

Can I use DateTime.Date directly in the formula bar?

Yes. With the step selected, type the function in the formula bar and press Enter. It works in custom columns, custom filters and any expression that returns a value.

Does it remove the time permanently from my source data?

No. It only changes the query output. The source file or database is untouched, and the original timestamp remains available in the query unless you delete that column.

Why does the column show a 12:00 AM time?

A date value stored with time set to midnight is displaying as a Date/Time. Change the column type to Date to hide the time portion.

Can I get the current date without a time?

Yes. Use DateTime.Date(DateTime.LocalNow()) to get today's date, or the UTC equivalent if your data uses UTC. The result refreshes when the query refreshes.

Will this work in Power BI and Excel the same way?

Yes. The M function is the same in both products, though the buttons that open the editor differ and labels can vary by version or region.