Powershell/Logparsing 转换数据类型

发布于 2024-11-17 20:11:33 字数 828 浏览 2 评论 0原文

我还在 powershell usenet 组上发布了这个,但我认为它现在基本上已经死了。

我正忙着写剧本。同时使用 powershell 和 日志解析器。我目前正在尝试将 csv 输入和输出放入 accdb。我有一个很好的工作脚本,但有一个问题。

我的字段之一应该是日期时间类型。然而导出的csv 从 powershell 通过 export-csv 使其成为一个字符串。我更愿意它 是日期时间格式。我研究了类型转换(使用 LogParser)并且 进入 ParseExact (使用 powershell),但我迷路了。

以下是导出 csv 生成的 csv 的示例:

"TIME","TEMP","HUMID","DEWPT"
"06/28/2011 12:53:13","70.9","79.8","63.6"
"06/28/2011 12:23:07","70.8","78.6","63.1"
"06/28/2011 11:53:00","70.8","78.9","63.2"
"06/28/2011 11:22:53","70.7","78.4","62.9"

这是我为 ParseExact(在 powershell 中)提出的内容:

{ [datetime]::ParseExact($_."TIME","MM'/'dd'/'YYYY' 'HH':'MM':'SS") }

如果您需要查看我用来将 csv 数据附加到 accdb 数据库让我知道,我会发布它。我对演员阵容在哪里没有偏好。我在 powershell 中创建 CSV,然后通过 logparser 将其复制到 Access 中的表中。

感谢您的关注。

I also posted this on the powershell usenet groups, but I think it is mostly dead now.

I am in over my head working on a script. Working with both powershell and
log parser. I am currently trying to take csv input and output into a
accdb. I have a good working script, with one problem.

One of my fields should be of type datetime. However the csv that exports
from powershell via export-csv makes it a string. I would prefer for it to
be a datetime format. I have looked into type casting (with LogParser) and
into ParseExact (with powershell), but I am lost.

Here is an example of what the csv that export-csv is making:

"TIME","TEMP","HUMID","DEWPT"
"06/28/2011 12:53:13","70.9","79.8","63.6"
"06/28/2011 12:23:07","70.8","78.6","63.1"
"06/28/2011 11:53:00","70.8","78.9","63.2"
"06/28/2011 11:22:53","70.7","78.4","62.9"

Here is what I've come up with for the ParseExact (in powershell):

{ [datetime]::ParseExact($_."TIME","MM'/'dd'/'YYYY' 'HH':'MM':'SS") }

If you need to see the code I am using to append the csv data into the
accdb database let me know and I'll post it. I have no preference on where the cast happens. I make the CSV in powershell and I copy it to a table in Access via logparser.

Thanks for looking.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文