Daten voneinander abziehen

  • Hallo =)

    Es geht um folgendes:
    Ich möchte eine Art Counter erstellen und möchte also ein Datum von einem anderen abziehen und das Ausgabeformat soll dann in
    Jahren, Monaten, Wochen, Tagen, Stunden, Minuten und Sekunden ausgegeben werden. Sekündlich wird dann der Counter hochgezählt.

    Derzeit habe ich mit _datediff in Sekunden mir die Differenz ausgeben lassen und daraus dann das Ausgabeformat, wie ich es wollte, errechnet.
    Doch... das Berechnen dauert bei nur 10 Tagen Differenz schon über eine Minute.

    Hätte da wer eine schnelle und sichere Funktion?

    Vielen Dank schonmal!

    Liebe Grüße
    Elodie

  • Beispiel für einen Stundencountdown und einen Tagescountdown:

    24 Stundencountdown:

    Spoiler anzeigen
    [autoit]


    #include <Date.au3>
    If _countDown("24:00:00") Then MsgBox(0, "CountDown", "Jipi") ; SS:MM:SS

    [/autoit] [autoit][/autoit] [autoit]

    Func _countDown($countdown)
    $begin = TimerInit()

    [/autoit] [autoit][/autoit] [autoit]

    Local $string = ""

    While 1
    $start = Round(TimerDiff($begin) / 1000)

    $countUp = StringFormat("%.02d" & ":" & "%.02d" & ":" & "%.02d", _
    Mod($start / 3600, 24), Mod(($start / 60), 60), Mod($start, 60))

    $sec = _DateDiff('s', "2006/01/01 " & $countUp, "2006/01/01 " & $countdown)
    If $sec = 0 Then Return 1

    $string = StringFormat("%.02d" & ":" & "%.02d" & ":" & "%.02d", _
    Mod($sec / 3600, 24), Mod(($sec / 60), 60), Mod($sec, 60))

    ToolTip($string)
    Sleep(100)
    WEnd
    EndFunc ;==>_countDown

    [/autoit]


    Countdown zum 31.12.2009 ; 23:59:59

    Spoiler anzeigen
    [autoit]


    #include<Date.au3>
    HotKeySet("{esc}", "end")
    ; "YYYY/MM/DD[ HH:MM:SS]"
    While 1
    ToolTip("Date" & @CRLF & "============" & @CRLF & _counter("2009/12/31", "23:59:59") & " left", _
    @DesktopWidth - 100, 30)
    Sleep(1)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ; "YYYY/MM/DD[ HH:MM:SS]"
    Func _counter($s_Date, $s_time)
    If _DateIsValid($s_Date & " " & $s_time) Then
    Local $NumberOfSeconds = _DateDiff("s", _NowCalc(), $s_Date & " " & $s_time)
    Return StringFormat("Days = %.02d" & @CRLF & "Hours = %.02d" & @CRLF & "Min = %.02d" & @CRLF & "Sec = %.02d" & @CRLF & _
    "Msec = %.03d", $NumberOfSeconds / 86400, Mod($NumberOfSeconds / 3600, 24), Mod(($NumberOfSeconds / 60), 60), _
    Mod($NumberOfSeconds, 60), 1000 - _MSec())
    Else
    Return -1
    EndIf
    EndFunc ;==>_counter

    [/autoit] [autoit][/autoit] [autoit]

    Func _MSec()
    Local $stSystemTime = DllStructCreate('ushort;ushort;ushort;ushort;ushort;ushort;ushort;ushort')
    DllCall('kernel32.dll', 'none', 'GetSystemTime', 'ptr', DllStructGetPtr($stSystemTime))
    $sMilliSeconds = StringFormat('%03d', DllStructGetData($stSystemTime, 8))
    $stSystemTime = 0
    Return $sMilliSeconds
    EndFunc ;==>_MSec

    [/autoit] [autoit][/autoit] [autoit]

    Func end()
    Exit (0)
    EndFunc ;==>end

    [/autoit]

    Das sollte helfen. Besonders weil vieles dazu in der Hilfe sehr gut erklärt ist. Aber wenn Du mal nicht weiter kommst, wir sind ja da ;)

    Lieben Gruß,
    Alina

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Geheime Information: ;)
    OuBVU5ebLhHu5QvlnAyQB4A7SzBrvWulwL7RLl2BdH5tI6sIYspeMKeXMSXl

    • Offizieller Beitrag

    Hallo,

    ich weiß ja nicht wie du rechnest aber das dauert bei mir nur wenige ms.

    Spoiler anzeigen
    [autoit]

    #include <Date.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $iYear = 2015
    $iMonth = 1
    $iDay = 1
    $iHour = 00
    $iMin = 00
    $iSec = 00

    [/autoit] [autoit][/autoit] [autoit]

    $iAltSec = 60

    [/autoit] [autoit][/autoit] [autoit]

    Do
    $iJahre = _DateDiff("Y", StringFormat("%4i/%02i/%02i %02i:%02i:%02i", @YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC), StringFormat("%4i/%02i/%02i %02i:%02i:%02i", $iYear, $iMonth, $iDay, $iHour, $iMin, $iSec))
    $iMonate = _DateDiff("M", _DateAdd("Y", $iJahre, StringFormat("%4i/%02i/%02i %02i:%02i:%02i", @YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC)), StringFormat("%4i/%02i/%02i %02i:%02i:%02i", $iYear, $iMonth, $iDay, $iHour, $iMin, $iSec))
    $iWochen = _DateDiff("W", _DateAdd("M", $iMonate, _DateAdd("Y", $iJahre, StringFormat("%4i/%02i/%02i %02i:%02i:%02i", @YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC))), StringFormat("%4i/%02i/%02i %02i:%02i:%02i", $iYear, $iMonth, $iDay, $iHour, $iMin, $iSec))
    $iTage = _DateDiff("D", _DateAdd("W", $iWochen, _DateAdd("M", $iMonate, _DateAdd("Y", $iJahre, StringFormat("%4i/%02i/%02i %02i:%02i:%02i", @YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC)))), StringFormat("%4i/%02i/%02i %02i:%02i:%02i", $iYear, $iMonth, $iDay, $iHour, $iMin, $iSec))
    $iStunden = _DateDiff("H", _DateAdd("D", $iTage, _DateAdd("W", $iWochen, _DateAdd("M", $iMonate, _DateAdd("Y", $iJahre, StringFormat("%4i/%02i/%02i %02i:%02i:%02i", @YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC))))), StringFormat("%4i/%02i/%02i %02i:%02i:%02i", $iYear, $iMonth, $iDay, $iHour, $iMin, $iSec))
    $iMinuten = _DateDiff("N", _DateAdd("H", $iStunden, _DateAdd("D", $iTage, _DateAdd("W", $iWochen, _DateAdd("M", $iMonate, _DateAdd("Y", $iJahre, StringFormat("%4i/%02i/%02i %02i:%02i:%02i", @YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC)))))), StringFormat("%4i/%02i/%02i %02i:%02i:%02i", $iYear, $iMonth, $iDay, $iHour, $iMin, $iSec))
    $iSekunden = _DateDiff("S", _DateAdd("N", $iMinuten, _DateAdd("H", $iStunden, _DateAdd("D", $iTage, _DateAdd("W", $iWochen, _DateAdd("M", $iMonate, _DateAdd("Y", $iJahre, StringFormat("%4i/%02i/%02i %02i:%02i:%02i", @YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC))))))), StringFormat("%4i/%02i/%02i %02i:%02i:%02i", $iYear, $iMonth, $iDay, $iHour, $iMin, $iSec))

    [/autoit] [autoit][/autoit] [autoit]

    If ($iAltSec <> $iSekunden) And ($iJahre >= 0) Then ConsoleWrite(StringFormat("%02i:%02i:%02i:%02i:%02i:%02i:%02i", $iJahre, $iMonate, $iWochen, $iTage, $iStunden, $iMinuten, $iSekunden) & @CRLF)
    $iAltSec = $iSekunden
    Sleep(200)
    Until $iJahre < 0

    [/autoit]