PowerShell的读取Excel中的日期为5位数字 [英] Powershell reading Excel date as 5 digit number

查看:516
本文介绍了PowerShell的读取Excel中的日期为5位数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用该<一个PowerShell脚本href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/04/use-ace-drivers-and-powershell-to-talk-to-access-and-excel.aspx"相对=nofollow> Powershell的模块。基本上,它可以让我查询Excel工作簿就像一个数据库。一切看起来都不错,除了它在读取日期作为靠不住的5位日期重新presentation,而不是一个日期。

I have a Powershell script that uses this Powershell module. It basically allows me to query Excel workbooks like a database. Everything looks good except it reads dates in as that wonky 5-digit date representation instead of a date.

我检查了列格式的文件本身和他们的格式为MM / DD / YYYY,因为他们应该的;我的脚本只是读他们的5位数字的日期。

I've checked the column formatting in the files themselves and they are formatted as MM/DD/YYYY as they should be; my script just reads them in as the 5-digit date.

例如:10年2月1日=> 40057

Example: 2/1/10 => 40057

我需要转换40057到合适的日期,或者使用一些原产于Powershell的(.NET),甚至forumla将设置我的权利。

I need to convert 40057 to the appropriate date, either using something native to Powershell (.NET), or even a forumla would set me right.

感谢。

推荐答案

你得到的数字,是天数,因为31/12/1899。

The number you get, is the number of days since 31/12/1899.

您可以将它通过使用AddDays增加数到.NET日期时间,也可以使用的 DateTime.FromOADate

You can convert it by adding the number to the .Net DateTime using AddDays, or you can use DateTime.FromOADate.

对不起,我不知道具体的PowerShell语法。

Sorry, I don't know the specific Powershell syntax.

有一点很奇怪这几天在1900年的头两个月

这篇关于PowerShell的读取Excel中的日期为5位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆