Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
1 like 0 dislike
709 views
in SQL Queries by 4 4 11

I have date in DB tabel with this format 01012023, and I need to format this date to be a readable date as below

01-01-2023

Can you help me to format this date as MM-DD-YYYY to can be used directly in Power BI without doing additonal transofmation in Power Query?


1 Answer

1 like 0 dislike
by 4 4 11
 
Best answer

How to format number to date in SQL?

To convert the number to date in SQL, you can use the below SQL query:

TRY_CONVERT(DATE, SUBSTRING(COLUMN_NAME, 7, 2) + '-' + SUBSTRING(COLUMN_NAME, 5, 2) + '-' + SUBSTRING(COLUMN_NAME, 1, 4), 105) AS FormattedDate

FormattedDate is just the name of the number column


See Also

If you don’t ask, the answer is always NO!
...