Power Query Date To Text

wsnyder

Board Regular
Joined
Sep 23, 2018
Messages
224
Office Version
  1. 365
Platform
  1. Windows
Hi all,
I am trying to convert a date to text in the format yyyymmdd.

If I enter = Date.ToText([RefDate]) I am able to convert a date to text.

But when I enter
Date.ToText([RefDate], [Format="yyyymmdd"])

I get an error:
Expression.Error: We cannot convert a value of type Record to type Text.
Details: Value= Format=yyyymmdd Type=[Type]


What am I doing wrong?
Thanks
-w
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You have to break it up into pieces, concatenate it, and then bring it together to convert to text.

Give this a shot:
Date.ToText(date#(Date.Year([RefDate])&","&Date.Month([RefDate])&","&Date.Day([RefDate)),[Format="yyyymmdd"])
 
Upvote 0
Hi all,
I am trying to convert a date to text in the format yyyymmdd.

If I enter = Date.ToText([RefDate]) I am able to convert a date to text.

But when I enter
Date.ToText([RefDate], [Format="yyyymmdd"])

I get an error:



What am I doing wrong?
Thanks
-w
Hello wsnyder,
Check the date column if there are any cells which have datetime format.....
 
Upvote 0
Hey Wsnyder,


There are a total of 17 format string options linked with the Date.ToText function. The interesting part is that you can combine these pieces in various ways to form a custom date string. For instance, using a particular arrangement yields the result "Sun December 31, 2023."

Power Query:
Date.ToText(
  #date( 2023, 12, 31 ),
  [Format="ddd MMMM d, yyyy"]
)


And this next string returns us 'november':

Power Query:
Date.ToText(
  #date( 2023, 11 5 ),
  [Format="MMMM", Culture="nl-NL"]
)
 
Last edited by a moderator:
Upvote 0
Since this has been resurrected, the issue with the original formula was that the 'mm' in the string means 'minutes' not 'months', which is 'MM' (M code being case sensitive). The error message is misleading (it seems to be better these days). So this:

Power Query:
Date.ToText([RefDate], [Format="yyyymmdd"])

just needs to be:

Power Query:
Date.ToText([RefDate], [Format="yyyyMMdd"])
 
Upvote 0
Since this has been resurrected, the issue with the original formula was that the 'mm' in the string means 'minutes' not 'months', which is 'MM' (M code being case sensitive). The error message is misleading (it seems to be better these days). So this:

Power Query:
Date.ToText([RefDate], [Format="yyyymmdd"])

just needs to be:

Power Query:
Date.ToText([RefDate], [Format="yyyyMMdd"])
Good point, it can be really confusing since yyyy and dd are accepted lowercase, where the M should be uppercase. I've found more of these for Time, DateTime and DateTimeZone confusing. You can find the different scenarios with examples written out clearly in this picture:


Cheers,
Rick
 
Upvote 0

Forum statistics

Threads
1,223,322
Messages
6,171,446
Members
452,404
Latest member
vivek562

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top