如何在Excel中将Oracle内部date转换为Exceldate?

我有一个从Oracle数据库捕获的.csv文件。 .csv文件中的date是Oracle内部格式(不确定是什么,因为我不熟悉Oracle)。 它看起来像16474

当我在用于访问数据库的应用程序中查看该date时,date是2/6/2013

但是,当我将.csv文件导入Excel并将该列格式设置为短date时,它将显示date为2/6/1945

我做了一个随机抽样,看起来月/日总是正确的,但是今年已经过去了68年。 我假设这是因为甲骨文的“开始时间”不同于Excel的“开始时间”

任何方式来解决这个问题,以便date显示正确时,将Oracle数据导入到Excel中?

我没有访问Oracle端的任何东西,只有.csv文件和Excel。 我也最终导入Excel文件到Access中,如果有帮助。

到目前为止,我在Excel中将Oracledate格式化为短date,并在我的date列(J)旁插入一列,并使用以下内容:

 =DATE(YEAR(J1)+68,MONTH(J1),DAY(J1)) 

考虑到闰年,我不确定这是否是100%准确的

编辑:我认为这个代码可能会做到这一点:

 Public Sub ReplaceData() Dim RangeCell As Range For Each RangeCell In Selection If IsNumeric(RangeCell.Value) Then lngDate = CLng(RangeCell.Value) RangeCell.Value = DateAdd("d", lngDate - 1, "1/1/1968") End If Next RangeCell End Sub 

甲骨文似乎可能在1/16/1968开始。 我不是一个数据库的人,但我认为这个数字听起来很熟悉,我已经做了其他的阅读。

如果上述假设为1/1/1968为真,则这是一个将Oracledate转换为Exceldate的例程。

 Sub OracleToExcelCSVDates() Dim rng as Range 'range of cells containing dates' Dim cl as Range Dim strDate As String 'date received from Oracle' Dim lngDate As Long Dim newDate As Date 'Converted date' Set rng = Range("J1:J1000") '< modify this for the number of rows you use in col J' For each cl in rng 'Iterate over the rng you defined above.' 'Capture the date from Oracle' strDate = cl.Value If Not Trim(strDate) = vbNullString Then 'ignore blanks' 'convert to Long data type' lngDate = CLng(strDate) 'Add the # of days (lngDate) to Oracles base date of 1/1/1968' newDate = DateAdd("d", lngDate - 1, "1/1/1968") 'Overwrite the cell value with the new converted date:' cl.Value = newDate End If End Sub 

有关Exceldate的更多信息:

Excel将连续date存储为“表示自1900年1月0日以来的天数的数字,再加上24小时日的小数部分:ddddd.tttttt。这称为连续date或连续date时间。

http://www.cpearson.com/excel/datetime