Dezimaldatum von Excel umwandeln

  • So, hier auch die passende Funktion, um das Exceldatum (Dezimal) in ein normales Ausgabeformat zu ändern

    Spoiler anzeigen
    [autoit]

    ; #FUNCTION#
    ;===============================================================================
    ;
    ; Name...........: _ExcelDateToNormaldate
    ; Description ...: Wandelt ein Excel Datum (Dezimal) in das Datum um (YYYY/MM/DD[ HH:MM:SS]) um
    ; Syntax.........: _ExcelDateToNormaldate($i_date)
    ; Parameters ....: $i_date - Das Datum, wie es von Excel ausgegeben wird
    ; Requirements...: _ExcelTimeToNormalTime()
    ; ...: #include <Date.au3>
    ; Return values .: Success - Das Datum im Format YYYY/MM/DD
    ; - Wenn $i_date Float ist, dann wird auch die Uhrzeit zurückgegeben YYYY/MM/DD HH:MM:SS
    ; Failure - Returns 0 and Sets @Error:
    ; |0 - Kein Fehler
    ; |1 - $i_date ist keine gültige Zahl
    ; Author ........: TheLuBu ([email='LuBu@veytal.com'][/email])
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........;
    ;
    ;==========================================================================================
    Func _ExcelDateToNormaldate($i_date)
    $i_date = StringReplace($i_date, ",", ".")
    If Not IsNumber($i_date) Then Return SetError(1, 0, 0)
    If IsInt($i_date) Then
    Return _DateAdd("d", $i_date, "1899/12/30")
    ElseIf IsFloat($i_date) Then
    $date = _DateAdd("d", Int($i_date), "1899/12/30")
    $hour = _ExcelTimeToNormalTime($i_date - Int($i_date))
    Return $date & " " & $hour
    EndIf
    EndFunc ;==>_ExcelDateToNormaldate
    ; #FUNCTION#
    ;===============================================================================
    ;
    ; Name...........: _ExcelTimeToNormalTime
    ; Description ...: Wandelt eine Exceluhrzeit (Dezimal) in eine normale Uhrzeit (hh:mm:ss) um
    ; Syntax.........: _ExcelTimeToNormalTime($i_time)
    ; Parameters ....: $i_time - Die Uhrzeit, wie sie von Excel gespeichert wird
    ; Return values .: Success - Die normale Uhrzeit
    ; Failure - Returns 0 and Sets @Error:
    ; |0 - Kein Fehler
    ; |1 - $i_time ist keine gültige Zahl
    ; Author ........: TheLuBu ([email='LuBu@veytal.com'][/email])
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........;
    ;
    ;==========================================================================================
    Func _ExcelTimeToNormalTime($i_time)
    $i_time = StringReplace($i_time, ",", ".")
    If Not IsNumber($i_time) Then Return SetError (1,0,0)
    Return StringRight("0" & Int($i_time * 24), 2) & ":" & StringRight("0" & Int((($i_time * 24) - Int($i_time * 24)) * 60), 2) & ":" & StringRight("0" & Int(((($i_time * 24) - Int($i_time * 24)) * 60 - Int((($i_time * 24) - Int($i_time * 24)) * 60)) * 60), 2)
    EndFunc ;==>_ExcelTimeToNormalTime
    ; #FUNCTION#
    ;===============================================================================

    [/autoit]
  • Hallo TheLuBu,

    nicht schlecht - aber zwei kleine Kritikpunkte habe ich:

    ein Tipp auf die nötigen Includes (#Include<Date.au3>) wäre super gewesen, ersparrt die Fehlersuche. Weiterhin ist mir ein Tippfehler aufgefallen. Du hast in Zeile 24 und 26 auf einmal ein Variable $iDate verwendet, sie müßte aber $i_Date heißen.

    MfG Jescho

    MfG Jescho

    Jeder hat mal klein angefangen - aber nicht jeder kommt groß raus!