Jump to content

Date Functions


sias
 Share

Recommended Posts

I am working on a script to calculate a set date with multiple variables being entered. Here is what I am attempting to do. I begin by entering a start date in the correct date format (YYYY/MM/DD MM:SS). Then using _dateadd I add a set number of days (usually around 100 or so, but this changes.), The next thing, and the part I am having trouble with is the subtraction portion of the script, I need to find a way to subtract another integer which includes days, hours and minutes. I have attempted to use _dateadd to do this as well, but I cant seem to figure out how to subtract the hours and minutes from the original date+added integer. Another question is what format would the "credittime input box" need to be in, in order to subtract the hours and minutes. Hopefully I wrote this so it is understandable in what exactly I need.

Any help would be much appreciated. Belong is the entire script, however the portion I need assistance with is located in the "Release Date and Time" and "Release Date Buttons" sections, and marked.

; ############################# Credit Time Calculator #############################
    GUICreate("Jail Credit Time Calculator", 550, 250, -1, -1)
    GUISetState()

    GUICtrlCreateGroup("Original Booking", 5, 5, 125, 95)
    GUICtrlCreateLabel("MM/DD/YYYY", 15, 20)
    GUICtrlCreateLabel("HH:MM", 15, 35)
    $bm = GUICtrlCreateInput("", 10, 50, 20, 20); booking month
    GUICtrlCreateLabel("/", 31, 52)
    $bd = GUICtrlCreateInput("", 40, 50, 20, 20); booking day
    GUICtrlCreateLabel("/", 61, 52)
    $by = GUICtrlCreateInput("", 70, 50, 30, 20); booking year
    $bhour = GUICtrlCreateInput("", 10, 75, 20, 20); booking hour
    GUICtrlCreateLabel(":", 33, 78)
    $bmin = GUICtrlCreateInput("", 40, 75, 20, 20); booking minutes

    GUICtrlCreateGroup("Original Release", 145, 5, 125, 95)
    GUICtrlCreateLabel("MM/DD/YYYY", 155, 20)
    GUICtrlCreateLabel("HH:MM", 155, 35)
    $rm = GUICtrlCreateInput("", 150, 50, 20, 20); release month
    GUICtrlCreateLabel("/", 170, 52)
    $rd = GUICtrlCreateInput("", 180, 50, 20, 20); release day
    GUICtrlCreateLabel("/", 201, 52)
    $ry = GUICtrlCreateInput("", 210, 50, 30, 20); release year
    $rhour = GUICtrlCreateInput("", 150, 75, 20, 20); release hour
    GUICtrlCreateLabel(":", 173, 78)
    $rmin = GUICtrlCreateInput("", 180, 75, 20, 20); release minutes

    GUICtrlSetLimit($bm, 2, 1)
    GUICtrlSetLimit($bd, 2, 1)
    GUICtrlSetLimit($by, 4, 2)
    GUICtrlSetLimit($bhour, 2, 1)
    GUICtrlSetLimit($bmin, 2, 1)

    GUICtrlSetLimit($rm, 2, 1)
    GUICtrlSetLimit($rd, 2, 1)
    GUICtrlSetLimit($ry, 4, 2)
    GUICtrlSetLimit($rhour, 2, 1)
    GUICtrlSetLimit($rmin, 2, 1)


    $calculate = GUICtrlCreateButton("Calculate", 20, 105, 100, 25)
    $reset = GUICtrlCreateButton("Reset", 150, 105, 100, 25)

    GUICtrlCreateGroup("Credit Time", 23, 138, 230, 45)
    $result = GUICtrlCreateInput("Credit Time", 30, 155, 215, 20)

; ############################# Release Date and Time #############################

    GUICtrlCreateGroup("Current Booking", 290, 5, 125, 95)
    GUICtrlCreateLabel("MM/DD/YYYY", 300, 20)
    GUICtrlCreateLabel("HH:MM", 300, 35)
    $cbm = GUICtrlCreateInput("", 295, 50, 20, 20); Current booking month
    GUICtrlCreateLabel("/", 316, 52)
    $cbd = GUICtrlCreateInput("", 325, 50, 20, 20); Current booking day
    GUICtrlCreateLabel("/", 347, 52)
    $cby = GUICtrlCreateInput("", 355, 50, 30, 20); Current booking year
    $cbhour = GUICtrlCreateInput("", 295, 75, 20, 20); Current booking hour
    GUICtrlCreateLabel(":", 318, 78)
    $cbmin = GUICtrlCreateInput("", 325, 75, 20, 20); Current booking minutes

    GUICtrlCreateGroup("Length and Credit Time", 425, 5, 115, 95)
    GUICtrlCreateLabel("Length (in days)", 435, 22)
    $sentlengthinput = GUICtrlCreateInput("", 435, 38, 75, 20)
    GUICtrlCreateLabel("Credit Time", 435, 60)
    $credittime = GUICtrlCreateInput("", 435, 75, 75, 20) ; #######################What format must this input box be in?

    $autocredittime = GUICtrlCreateButton("<--", 515, 75, 20, 20)
    $calculatecurrent = GUICtrlCreateButton("Calculate", 300, 105, 100, 25)
    $resetcurrent = GUICtrlCreateButton("Reset", 430, 105, 100, 25)

    GUICtrlSetLimit($cbm, 2, 1)
    GUICtrlSetLimit($cbd, 2, 1)
    GUICtrlSetLimit($cby, 4, 2)
    GUICtrlSetLimit($cbhour, 2, 1)
    GUICtrlSetLimit($cbmin, 2, 1)

    GUICtrlCreateGroup("Release Date and Time", 302, 138, 230, 45)
    $creldate = GUICtrlCreateInput("Release Date and Time", 310, 155, 215, 20)

    $close = GUICtrlCreateButton("Close", 225, 195, 100, 25)

; ############################# Menu ###########################################
    $menu = GUICtrlCreateMenu("Menu")
    $CheckMenu = GUICtrlCreateMenuItem("Always on Top",$Menu)
    $aboutitem = GUICtrlCreateMenuItem("About", $menu)
    $closeitem = GUICtrlCreateMenuItem("Close", $menu)
    $menuspacer = GUICtrlCreateMenu( "  " )
    $menudate = GUICtrlCreateMenu(@MON & "/" & @MDAY & "/" & @YEAR)
; ############################# Credit Time Buttons #############################

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $calculate

                $vara = GUICtrlRead($bm)
                $varb = GUICtrlRead($bd)
                $varc = GUICtrlRead($by)
                $vard = GUICtrlRead($rm)
                $vare = GUICtrlRead($rd)
                $varf = GUICtrlRead($ry)
                $varg = GUICtrlRead($bhour)
                $varh = GUICtrlRead($bmin)
                $vari = GUICtrlRead($rhour)
                $varj = GUICtrlRead($rmin)
                $bktime = StringFormat("%s/%s/%s %s:%s", $varc, $vara, $varb, $varg, $varh)
                $reltime = StringFormat("%s/%s/%s %s:%s", $varf, $vard, $vare, $vari, $varj)

                $DateCalcD = _DateDiff('D', $bktime, $reltime)
                $DateCalch = _DateDiff('h', $bktime, $reltime)
                $DateCalcm = _DateDiff('n', $bktime, $reltime)
                GUICtrlSetData($result, $DateCalcD & " Days " & Int($DateCalch - $DateCalcD * 24) & " Hours " & _
                        Int($DateCalcm - $DateCalch * 60) & " Minutes ")
            Case $msg = $reset
                GUICtrlSetData($bm, "")
                GUICtrlSetData($bd, "")
                GUICtrlSetData($by, "")
                GUICtrlSetData($bmin, "")
                GUICtrlSetData($bhour, "")
                GUICtrlSetData($rm, "")
                GUICtrlSetData($rd, "")
                GUICtrlSetData($ry, "")
                GUICtrlSetData($rmin, "")
                GUICtrlSetData($rhour, "")
; ############################# Release Date Buttons #############################
            Case $msg = $autocredittime
                GUICtrlSetData($credittime, $DateCalcD & "D:" & Int($DateCalch - $DateCalcD * 24) & "H:" & _
                        Int($DateCalcm - $DateCalch * 60) & "M") ; ####################### Modify this line based on format for credittime input box.

            Case $msg = $calculatecurrent
                $vark = GUICtrlRead($cbm)
                $varl = GUICtrlRead($cbd)
                $varm = GUICtrlRead($cby)
                $varn = GUICtrlRead($cbhour)
                $varo = GUICtrlRead($cbmin)
                $ctime = guictrlread($credittime)
                $cbookdate = StringFormat("%s/%s/%s %s:%s", $varm, $vark, $varl, $varn, $varo)
                $sentlength = GUICtrlRead($sentlengthinput)
                $reldate = _DateAdd("D", $sentlength, $cbookdate)
                $finalreldate = _DateAdd("D", -$ctime, $reldate & _DateAdd("h", -$ctime, $reldate) & _DateAdd("n", -$ctime, $reldate))
                
                GUICtrlSetData($creldate, $finalreldate)


            Case $msg = $resetcurrent
                GUICtrlSetData($cbm, "")
                GUICtrlSetData($cbd, "")
                GUICtrlSetData($cby, "")
                GUICtrlSetData($cbmin, "")
                GUICtrlSetData($cbhour, "")
                GUICtrlSetData($sentlengthinput, "")
                GUICtrlSetData($credittime, "")


; ############################# Menu #############################
            Case $msg = $CheckMenu
            If BitAND(GUICtrlRead($CheckMenu), $GUI_CHECKED) = $GUI_CHECKED Then
            WinSetOnTop( "Jail Credit Time Calculator", "", 0)
                GUICtrlSetState($CheckMenu, $GUI_UNCHECKED)
            Else
            WinSetOnTop( "Jail Credit Time Calculator", "", 1)
                GUICtrlSetState($CheckMenu, $GUI_CHECKED)
            EndIf
            Case $msg = $aboutitem
                MsgBox(0, "About", "Credit Time Calculator" & @CRLF & @CRLF & "Created by Jeremy Brice" & @CRLF & @CRLF & "Version 2.3 Build 6508" & @CRLF & "Copyright© 2008")
            Case $msg = $closeitem
                Exit
            Case $msg = $close
                Exit
                Exit
        EndSelect
    WEnd
EndIf

"The true measure of a man is how he treats someone who can do him absolutely no good."

Link to comment
Share on other sites

I am working on a script to calculate a set date with multiple variables being entered. Here is what I am attempting to do. I begin by entering a start date in the correct date format (YYYY/MM/DD MM:SS). Then using _dateadd I add a set number of days (usually around 100 or so, but this changes.), The next thing, and the part I am having trouble with is the subtraction portion of the script, I need to find a way to subtract another integer which includes days, hours and minutes. I have attempted to use _dateadd to do this as well, but I cant seem to figure out how to subtract the hours and minutes from the original date+added integer. Another question is what format would the "credittime input box" need to be in, in order to subtract the hours and minutes. Hopefully I wrote this so it is understandable in what exactly I need.

The 'secret'.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks for the link, however I am able to subtract days correctly, the problem I am having is with subtracting the hours and minutes from the date along with the days. Any ideas on the how I would go about doing that?

"The true measure of a man is how he treats someone who can do him absolutely no good."

Link to comment
Share on other sites

Thanks for the link, however I am able to subtract days correctly, the problem I am having is with subtracting the hours and minutes from the date along with the days. Any ideas on the how I would go about doing that?

Same answer, you just do the math to convert to the smallest unit you want to work with (i.e. days, hours, minutes, or seconds) and add (or multiply by -1 to subtract) the value. For example, to subtract 2 day, 3 hours, 4 minutes, and 5 seconds:
#include <Date.au3>
$sRET = _DateAdd("s", -1 * ((2 * 86400) + (3 * 3600) + (4 * 60) + 5), _NowCalc())
MsgBox(64, "Result", "2 days, 3 hours, 4 minutes, and 5 seconds ago was:  " & $sRET)

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Same answer, you just do the math to convert to the smallest unit you want to work with (i.e. days, hours, minutes, or seconds) and add (or multiply by -1 to subtract) the value. For example, to subtract 2 day, 3 hours, 4 minutes, and 5 seconds:

#include <Date.au3>
$sRET = _DateAdd("s", -1 * ((2 * 86400) + (3 * 3600) + (4 * 60) + 5), _NowCalc())
MsgBox(64, "Result", "2 days, 3 hours, 4 minutes, and 5 seconds ago was:  " & $sRET)

:)

Thank you very much for you help, I just couldnt figure out that math formula. But that did the trick, and with the addition of that code my program is complete (until I think of something else cool to add) :).

Thanks again for your help and for the help of the entire Autoit Community for keeping it alive!

Edited by Sias88

"The true measure of a man is how he treats someone who can do him absolutely no good."

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...