英文:
PowerQuery Date formats with leading blanks
问题
日志文件中的日期部分的格式如下:
Fri Jun 30 19:50:10 2023
出于某种奇怪的原因,日志记录软件会在时间(19:50 / 09:50等)前添加一个前导零,但对于日期(30 Jun / 1 Jul等),它不会添加相同的前导零,而是添加一个前导空格。
这会导致我的新自定义列基于以下内容出现问题:
DateTime.FromText([tDateTime],[Format="ddd MMM dd HH:mm:ss yyyy", Culture="en-US"])
我已经尝试了显而易见的方法(使用单个'd'而不是双个'd',以及包含前导空格,所有这些都会在我输入1 Jul时立即导致错误。我无法在这里或通过Google教授找到任何有关信息。
英文:
The log file that I have to use as a data source contains a date section in the form:
Fri Jun 30 19:50:10 2023
For some bizarre reason the logging software adds a leading zero to times (19:50 / 09:50 etc) but doesn't do the same for dates (30 Jun / 1 Jul) instead, it adds a leading space.
This breaks my new custom column based on:
DateTime.FromText([tDateTime],[Format="ddd MMM dd HH:mm:ss yyyy", Culture="en-US"])
I've tried the obvious (single 'd' rather than double and including a leading space all of which result in an error as soon as I hit 1 Jul I've not been able to find anything here or via Prof. Google
答案1
得分: 2
如果没有人接手并发布更优雅的解决方案...
经过一番尝试和错误,我找到了一个解决方法:
DateTime.FromText(Text.Replace(Text.Range([Column1],0,24)," "," "),[Format="ddd MMM d HH:mm:ss yyyy", Culture="en-US"])
这将双空格替换为单空格,使格式能够正常工作。
英文:
In case no one picks this up and posts a more elegant solution...
After a fair bit of trial and error, I found a workaround:
DateTime.FromText(Text.Replace(Text.Range([Column1],0,24)," "," "),[Format="ddd MMM d HH:mm:ss yyyy", Culture="en-US"])
This replaces the double space with a single one allowing the format to work.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论