Power Query* can easily take a column of dates and extract, or convert it into various handy date formats with the click of a few buttons.
For example, the dates in the first column of the table below have been used to quickly create new columns displaying various date information:
The above examples are just a taste of what is possible. There’s a huge list of options in the Date menus available from the Add Column tab, which will keep your original date column and add a new one in the format you choose, or from the Transform tab, which will convert the selected date column.
Below is a preview of the options currently available (note: select the Date column first to enable the menu):
*Power Query is available for Excel 2010 onwards.
Download the workbook
Enter your email address below to download the sample workbook.
Working with Power Query Date Formats
We’ll use this simple table containing dates and sales amounts as our source data. Notice that the table is called ‘Table1’:
Note: My dates are formatted dd/mm/yyyy.
Load to Power Query
In Excel 2010/2013: Power Query tab > From Table or in Excel 2016: Date tab > From Table:
This will open the Power Query Editor window where you will find the Date tools on both the Transform tab, which changes the format of the selected date column:
Or the Add Column tab, which adds a column based on the selected date column:
Have a play around with the different options available.
- Date > Age calculates the age in days from the date column date to today’s date.
- Date > Date Only removes any time element from the Date field and just returns the Date portion.
- On the Transform tab, Date > Earliest returns the earliest date in the selected column, and Latest returns the latest date.
- On the Add Column tab, Date > Earliest and Latest require two date columns to be selected. It then creates a new column containing the earliest/latest date for each row.
- You can also work with time values in the same way. See the Time menu on both the Add Column and Transform tabs:
Older Versions of Power Query
Some of the date menu items are new. For example, if your version of Power Query is missing the Month Name, or Day Name then you can achieve the same results by adding a Custom Column (Add Column tab) and using the Date.ToText function. Here are some examples:
Date to Month Name (MMM format)
Create a new column for the month name (note: this will be a text field).
- Select the Date column
- Add Column tab
- Custom Column
- Give your new column a name and enter this formula (change the [Date] column name to suit your file):
= Date.ToText([Date], "MMM")
- Click OK to enter the formula and create the column
Caution: Power Query formulas are case sensitive. Upper case ‘M’ refers to month format, whereas lower case ‘m’ is for minutes. For example:
= Date.ToText([Date], "MMM")
Will return the text, ‘Jan’ from the date 1/1/2017.
= Date.ToText([Date], "MMMM")
Will return the text, ‘January’ from the date 1/1/2017.
Will simply return the date value as text in the same format it’s in.
Date to Day Name
Likewise, we can use the Date.ToText function to convert the date to the day name:
Will return the text value ‘Sun’ from the date 1/1/2017.
Will return the text value ‘Sunday’ from the date 1/1/2017.
Tip: Be sure to set the data type for these custom columns containing text names of dates to the Date Type: Text:
More Power Query
Click here for more Power Query tutorials.
And if you want to get up to speed quickly, please check out my Power Query course.
Thank you for your help with the short day (Name) function, print screens were greatly appreciated.
Great to hear, Jayson!
Darwis Yudi Brata
How to make month name locale? i try to change type locale but when i transform to month name, it”s in en-ID. I want in id-ID
You can specify the culture in Date.Month function:
Date.MonthName(#datetime(2011, 12, 31, 5, 0, 0), “id-ID”)
What can I do to best display information where any date today on is ok in date format but anything before I want to show as past due in the same column so that I can make a pivot table showing my demand?
Hi Kayla, you can use Conditional Formatting to highlight overdue dates.
As my company’s excel version is old, i can’t use “Name of month” function straightly. I spend lots of time to search a good resolution online and don’t figure it out until find your article!!!! Thanks a lot!
Glad it was helpful, Rita!
Glad you liked it, Prakash!
Still a bit of a Power Query/Get & Transform noob!
I understand how to use the locale to transform US to UK dates. However I have a column of dates (as text) in both US and UK formats (as well as some blanks). Fortunately, I have a corresponding culture column (mainly “en-GB” and “en-US”, with a random “en-IN” – equivalent to “en-GB”).
How do I transform the column text to UK dates using the cultures? I’m guessing I have to delve into the formula bar but wondering if there’s a more obvious method?
Recently discovered your videos on YouTube and must say they’re extremely useful and clearly explained … even the topics I’m unlikely to use!
All the best,
Add a Custom Column and use the Date.FromText function like so:
#”Added Custom1″ = Table.AddColumn(#”Added Custom”, “Custom”, each Date.FromText([Date],[Culture]))
where [Date] is the column with your dates and [Culture] is the column with your culture codes.
Thanks Phil. Perfect – worked like a charm.
I have a column named “Customer Visible Date” and would like to filter it to everything equal to today and all the dates less than today in my Excel Power Query.
You can use the DateTime.LocalNow Power Query function to filter based on the current date. If you’re not sure where to go from here, please post your question on our Excel forum and share a sample Excel file so we can help you further.
When I use the abbreviated month as a slicer, it puts the month in alphabetical order instead of Month order. Is there a way ti force it to show in month order?
It’s better to use proper dates in your PivotTables and then use the PivotTable Group functionality to group them into months, years etc. so that Excel knows how to sort the month names. Alternatively, you can use a Custom List to sort the Slicer or use a numeric field e.g. yyyy-mm as explained here.
What if you don’t have a date column, but want to have one with the date the data was imported?
You can ‘Add a Column’ and use the DateTime.LocalNow function to timestamp the query, but obviously every time you refresh the query the DateTime.LocalNow would also return the current date, so that may not suit your needs. The alternative is to manually enter that date via ‘Add a Column’.
Thanks for the post.
My question is regarding the use of PowerPivot. Can I use it data formated as dd/mm/yy or I should first convert it to mm/dd/yy?
My input data comes from files in the following date format:
* I have tried creating a date table manually, by entering pasting dates in format dd/mm/yy but as soon as they are pasted, excel converts them into format mm/dd/yy
* I went to the queries and defined the dates as European local format dd/mm/yy
Yet, when I use the month as slicer on power pivot, I can see dates are recognized as american dates.
01/01/18 is recognized as January 1st, 2018. This OK, no room for mistake.
02/01/18 is recognized as February 1st, 2018. In fact it is, January 2nd, 2018
03/01/18 is recognized as March 1st, 2018. In fact it is, January 3rd, 2018
I would be very greateful if anyone could help me out.
You need to remove the ‘Changed Type’ step in the ‘Applied Steps’ pane. Then right-click the date column header > change type > Using Locale. In the dialog box choose data type: Date. Then choose English (UK) from the drop down list. This should format your dates as dd/mm/yyyy assuming your source data has regional settings of dd/mm/yyyy.
Hello, is there an easy way to add a number of weekdays to a date? I have a column with the number of days I need to add and a column with the date I need to add them to. I’m using PowerQuery plugin to excel 2010. Thanks!
No easy way, but there is a function already made, you can try it: https://stackoverflow.com/questions/42099667/add-x-number-of-working-days-to-a-date-in-a-custom-column
This worked great – thank you!
You’re welcome 🙂
I’m using Power Query and am having trouble with week of year and figuring out how to start the week on Monday. Any idea how to update the query?
If you look at the M code that’s generated when you insert the Start of Week column you’ll see that it uses the Date.StartOfWeek function. This function has a second argument that allows you to specify the first day of the week. e.g.
More on the Date.StartOfWeek function here: https://msdn.microsoft.com/en-us/library/mt260707.aspx
Hi, thanks for your post, but for the name of the day or the name of month, you have :
Name of Day : Date.DayOfWeekName([Date])
Name of Month : Date.MonthName([Date])
You can add the culture (French for me) :
And instead of having text value, you have a date value !
I used the GUI to add the day of week etc. and it doesn’t ask for a locale/culture. I only have an English version of Power Query so I’m curious to know if your version has a field in the dialog that asks what region, or do you have to add it manually by editing the M Code?
works for me.. Thanks for the tips….
You’re welcome, Peter 🙂