Jump to content
Sign in to follow this  
ant2ne

managing dates

Recommended Posts

ant2ne

I've got a program that outputs some data into a text file like so...

 

2013-08-22 finished successfully

2013-08-19 finished successfully
2013-08-18 finished successfully
2013-08-17 finished successfully
2013-08-16 finished successfully
2013-08-15 finished successfully

Since it didn't report anything on the 20th and the 21st, I assume it failed. I'd like to fill in those missing lines with the appropriate dates and "failed", but I don't know how to decrement and stay in line with the dates since calendars aren't based on the 10 count. The day before the 1st might be a 30 a 31 28 etc. Is there a nifty date type function I can toss those dates into and have it spit out what I need?

Share this post


Link to post
Share on other sites
Melba23

ant2ne,

No, but you can do it pretty easily like this: ;)

#include <Array.au3>
#include <Date.au3>

; Use _FileReadToArray to get an array
Local $aArray[] = [6, _
            "2013-08-22 finished successfully", _
            "2013-08-19 finished successfully", _
            "2013-08-18 finished successfully", _
            "2013-08-17 finished successfully", _
            "2013-08-16 finished successfully", _
            "2013-08-15 finished successfully"]

; Work up through array elements
For $i = $aArray[0] To 2 Step -1

    $sDate_1 = StringReplace(StringLeft($aArray[$i], 10), "-", "/")
    $sDate_2 = StringReplace(StringLeft($aArray[$i - 1], 10), "-", "/")
    ; Check dates are 1 day apart
    If _DateDiff("D", $sDate_1, $sDate_2) <> 1 Then
        ; If not then determine the missing date
        $sMissing_Date = StringReplace(_DateAdd("D", 1, $sDate_1), "/", "-")
        ; And add it to the array
        _ArrayInsert($aArray, $i, $sMissing_Date & " - failed")
        ; Reset the counter
        $i += 1

        _ArrayDisplay($aArray) ; Just for display

    EndIf

Next

; And then you rewrite this array with _FileWriteFromArray
_ArrayDisplay($aArray, "Ended")
All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
ant2ne

Awesome code thanks. With a little tweaking it works. 

Share this post


Link to post
Share on other sites
Melba23

ant2ne,

My pleasure. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×