Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
The source data I'm trying to convert is in text format as "20201201 163045". I'm using to_timestamp and returning a value "12/01/2020 4:30:45 PM".
This is SQL I'm using:
to_timestamp(txndatetime, 'yyyy-mm-dd HH24:mi:ss') As EventDate
How do I get this to return the date time in 24 hour format?
Solved! Go to Solution.
In your original text column (with 20201201 163045), you can do a Replace Values step and replace the space with a "T". Then you can add a custom column with this formula to get your result.
= DateTime.ToText(DateTime.FromText([DateTimeText]), "MM/dd/yy HH:mm:ss")
Or (recommended) just use
= DateTime.FromText([DateTimeText])
And then use a format string after you load the query on that column to display it with that format (in quotes above). That way it will stay as a DateTime instead of text.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
In your original text column (with 20201201 163045), you can do a Replace Values step and replace the space with a "T". Then you can add a custom column with this formula to get your result.
= DateTime.ToText(DateTime.FromText([DateTimeText]), "MM/dd/yy HH:mm:ss")
Or (recommended) just use
= DateTime.FromText([DateTimeText])
And then use a format string after you load the query on that column to display it with that format (in quotes above). That way it will stay as a DateTime instead of text.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
@mahoneypat , how would you convert text to datetime if the text is written, "01/23/2024 1:23 PM PST?" The above formulae doesn't work in this case and the timezone would be important. Thanks.
Worked perfectly, thank you very much 🙂
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 4 | |
| 3 | |
| 3 |
| User | Count |
|---|---|
| 14 | |
| 11 | |
| 8 | |
| 7 | |
| 6 |