Datum minus eine Tag

  • Hallo Leute,
    ich brauch mal wieder eure Unterstützung,
    ich hab mir ein kleines Programm zusammen gebastelt das in einer Webseite nach einem String sucht und dann wenn gefunden eine Nachricht sendet.
    Wenn nix gefunden wurde einen Eintrag in eine Datei schreibt. Fertig.
    Nun suche ich nach Ausdruck und Datum minus einem Tag also:
    $Suchstring = $a_prog & "-" & @YEAR & @Mon & @mday -1
    Leider ist es so, das wenn die Tage 1 -10 sind, das Datum die führende Null nicht mitschreibt.
    ohne "-1" wird das Datum wie folgt angezeigt:
    20131105
    wenn ich einen Tag abziehe also @mday -1 dann kommt folgendes raus.
    2013114
    Ich benötige aber die "0", da ich nach eiem Textstring suche.
    kann mir jemand sagen wie ich das lösen kann?

    Vielen Dank
    Gruß
    Manfred
    PS: Hier der komplette Code.

    [autoit]


    ; Alarm
    #Include<file.au3>
    #include <INet.au3>

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

    Global $a_file = ("Mailconf.ini")
    Global $a_prog = IniRead($a_file, "programm", "prog", "")
    Global $a_e_mail = IniRead($a_file, "Mail", "mail_e", "")
    Global $a_c_mail = IniRead($a_file, "Mail_cc", "mail_c", "")
    Global $a_server = IniRead($a_file, "server", "server_url", "")

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

    $Source = (_INetGetSource($a_server & '/dumplogs'))
    ConsoleWrite($Source)

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

    $Dateipfad = $Source
    ; Im Suchstring sind die Anzahl der Tage die rückwirkend gesucht werden angegeben.
    $Suchstring = $a_prog & "-" & @YEAR & @Mon & @mday -1
    $Dateitext = FileRead($Dateipfad)
    If StringInStr($Source, $Suchstring) Then
    ; MsgBox(0,"", $Suchstring &" wurde gefunden!")
    ; email()
    Else

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

    $file = FileOpen("test.txt", 1)

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

    ; Prüfen, ob Datei im Schreibmodus geöffnet ist
    If $file = -1 Then
    MsgBox(0, "Fehler", "Die Datei konnte nicht geöffnet werden.")
    Exit
    EndIf

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

    FileWriteLine($file, $a_prog & " wurde am " & @mday & "." & @MON & "." & @year &" nicht gefunden!")
    FileWriteLine($file, " " & @CRLF)
    FileWriteLine($file, "==========================================================")

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

    FileClose($file)

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

    Exit
    ; MsgBox(0,"", "nichts gefunden")
    EndIf

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

    ; Func email()

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

    Local $Nachricht = "Dumplog CAS* M3 Produktion (DEBI-M3PROD01.boellhoff.de:6666/dumplogs)"

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

    $SmtpServer = "Server" ; address des smtp-server - BENOETIGT
    $FromName = "Produktion" ; name des Absenders
    $FromAddress = "MailServer@Domain.com" ; Absender E-Mail Adresse
    $ToAddress = $a_e_mail ; Empängeradresse - BENOETIGT
    $Subject = $Nachricht ; Betreffzeile der E-Mail
    $Body = $Source ; & $Suchstring ; Inhalt der Mail
    $AttachFiles = "" ; Anhang (Die Mail kann mit einem Anhang versehen werden.)
    $CcAddress = ""; $a_c_mail ; Adresse des Kopie Empfängers
    $BccAddress = "" ; Adresse einer Blindkopie
    $Importance = "Normal" ; Prioritaet: "High", "Normal", "Low"
    $Username = "" ; Username fuer die Authentifizierung am SMTP Server falls erforderlich
    $Password = "" ; Passwort fuer die Authentifizierung am SMTP Server falls erforderlich
    $IPPort = 25 ; SMTP Port wird fuer den Versand benoetigt
    $ssl = 0 ; enables/disables ssl fuer Verschluesselte Mails (https) 1 angeben
    ;~ $IPPort=465 ; Verschluesslete Mails benötigen den port 465

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

    ;##################################
    ; Script
    ;##################################
    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
    $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
    If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)
    EndIf
    ;
    ; The UDF
    Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    Local $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
    $objEmail.HTMLBody = $as_Body
    Else
    $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
    Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
    For $x = 1 To $S_Files2Attach[0]
    $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
    ;~ ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
    If FileExists($S_Files2Attach[$x]) Then
    ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
    $objEmail.AddAttachment($S_Files2Attach[$x])
    Else
    ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
    SetError(1)
    Return 0
    EndIf
    Next
    EndIf
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    If Number($IPPort) = 0 then $IPPort = 25
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
    ;Authenticated SMTP
    If $s_Username <> "" Then
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
    If $ssl Then
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Set Email Importance
    Switch $s_Importance
    Case "High"
    $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
    Case "Normal"
    $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
    Case "Low"
    $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
    SetError(2)
    Return $oMyRet[1]
    EndIf
    $objEmail=""
    EndFunc ;==>_INetSmtpMailCom
    ;
    ;
    ; Com Error Handler
    Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
    EndFunc ;==>MyErrFunc

    [/autoit]

    Ja, ich weiß es auch, das Problem ist einen halben Meter vor dem Bildschirm. 8o

    Einmal editiert, zuletzt von Mr-Ferret (5. November 2013 um 12:08)

  • Wenn es allerdings auch für die Monats- bzw. Jahresgrenze hinweg funktionieren soll würde ich _DateAdd verwenden.
    Dann wird z. B. aus 01.11.2013 der 31.10.2013

  • Fast die gleiche Frage wurde hier auch gestellt: Klick Mich
    Die gleiche Methode funktioniert natürlich auch mit -1 statt 1. Vorteil ist, dass man sich um Formatierungen, Unterläufe (z.B. am Monatsanfang), usw. keine Gedanken machen muss, das übernimmt die UDF schon automatisch
    lg
    M