代码之家  ›  专栏  ›  技术社区  ›  Anthony

excel中的Julian日期至年月日

  •  1
  • Anthony  · 技术社区  · 17 年前

    我正在尝试将儒略日期(yy/ddd)转换为excel vba中的常规mm/dd/yy数据。我有一个想法,就是使用一个selectcase语句,为每个月调用一个函数。但这是很多代码,我很懒。我想知道有没有更好的办法?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Community Mohan Dere    8 年前

    根据 this website

    =DATE(IF(0+(LEFT(A1,2))<30,2000,1900)+LEFT(A1,2),1,RIGHT(A1,3))
    

    只要A1中有一个五位数的数字,它就可以工作。例如,它将95032变为2/1/1995。如果数据中有斜杠(95/032),则需要调整公式。

    Function JDateToDate(JDate As String) As Long
    Dim TheYear As Integer
    Dim TheDay As Integer
    Dim TheDate As Long
    
    TheYear = CInt(Left(JDate, 2))
    If TheYear < 30 Then
        TheYear = TheYear + 2000
    Else
        TheYear = TheYear + 1900
    End If
    
    TheDay = CInt(Right(JDate, 3))
    TheDate = DateSerial(TheYear, 1, TheDay)
    JDateToDate = TheDate
    
    End Function
    

    Ordinal Date