Jump to content

Date and Time change


sias
 Share

Recommended Posts

Hopefully I can get this across with all the correct information, and explain fully what I am attempting to do. Firstly let me start with the intent of my program, it is designed to help figure the credit time of a person being processed in to jail. The way credit time works is when someone is first brought in on charges, if they bond out, and are sentenced, they still get the credit for the time they were in jail before they were bonded out.

However, currently when we figure credit time all we have is their book in date/time, and their book out date/time. I am writing this program in an attempt to simplify the process of us figuring their credit time. What I need is for a mathmatical formula that will subtract their release date and time, from their booking date and time. I have the entire GUI set up, however, I cannot figure out what the formula would be to figure out the actual credit time. Thanks in advance for any help you may be able to give, below is the working script (without the correct formula that is). [Attached is the .au3 file]

The code I need to modify with the correct mathmatical formula

GUICtrlSetData( $result, $vard-$vara & " " & "Months" & " " & $vare-$varb & " " & "Days" & " " & $varf-$varc & " " & "Years" & " " & $vari-$varg & " " & "Hours" & " "& $varj-$varh & " " & "Minutes" )

The entire code

#include <GUIConstants.au3>
#include <GuiEdit.au3>
GUICreate ( "Jail Credit Time Calculator", 275, 250, -1, -1 )
GUISetState () 

$menu = GuiCtrlCreateMenu ("Menu")
$aboutitem = GuiCtrlCreateMenuitem ("About",$menu)
$closeitem = GuiCtrlCreateMenuitem ("Close",$menu)
$menuspacer = GuiCtrlCreateMenu ( "                                                 " )
$menudate= GUICtrlCreateMenu( @MON & "/" & @WDAY & "/" &@YEAR )


GUICtrlCreateGroup("Booking Date and Time", 5, 5, 125, 95)
GUICtrlCreateLabel ("MM/DD/YYYY", 15, 20)
GUICtrlCreateLabel ("HH:MM", 15, 35)
$bm= GUICtrlCreateInput ( "", 10, 50, 20, 20 ); booking month
GUICtrlCreateLabel ("/", 32, 52)
$bd= GUICtrlCreateInput ( "", 40, 50, 20, 20 ); booking day
GUICtrlCreateLabel ("/", 62, 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("Release Date and Time", 145, 5, 125, 95)
GUICtrlCreateLabel ("MM/DD/YYYY", 155, 20)
GUICtrlCreateLabel ("HH:MM", 155, 35)
$rm= GUICtrlCreateInput ( "", 150, 50, 20, 20 ); release month
GUICtrlCreateLabel ("/", 171, 52)
$rd= GUICtrlCreateInput ( "", 180, 50, 20, 20 ); release day
GUICtrlCreateLabel ("/", 202, 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)
$close= GUICtrlCreateButton ( "Close", 85, 135, 100, 25)


GUICtrlCreateGroup("Credit Time", 23, 160, 230, 65)
$result= GUICtrlCreateInput ( "Credit Time", 30, 175, 215, 40 )

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 ) 
        
           GUICtrlSetData( $result, $vard-$vara & " " & "Months" & " " & $vare-$varb & " " & "Days" & " " & $varf-$varc & " " & "Years" & " " & $vari-$varg & " " & "Hours" & " "& $varj-$varh & " " & "Minutes" )
       case $msg= $reset
            guictrlsetdata( $bm, "" )
            guictrlsetdata( $bd, "" )
            guictrlsetdata( $by, "" )
            guictrlsetdata( $bmin, "" )
            guictrlsetdata( $bhour, "" )
            guictrlsetdata( $rm, "" )
            guictrlsetdata( $rd, "" )
            guictrlsetdata( $ry, "" )
            guictrlsetdata( $rmin, "" )
            guictrlsetdata( $rhour, "" )
        case $msg= $close
           Exit
               Case $msg = $aboutitem
            Msgbox(0, "About", "Credit Time Calculator" & @crlf & @crlf & "Created by Jeremy Brice" & @CRlf & @crlf &  "Version 1.3 Build 4509" & @CRlf & "Copyright© 2008")
            Case $msg = $closeitem
            Exit
    Exit
EndSelect
WEnd
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

_DateAdd() wasn't exaclty what I was looking for in this situation, but I will definitely be using it for the next portion of my script. However, you pointing it out did lead me to _DateDiff(). I have updated the script to use _DateDiff(), however Is it possible to have it return an exact value? What I mean is, if I put in a booking date of 2008/5/12 5:15 and a release date of 2008/5/13 5:20. With my current script it returns the following "1 Days 24 Hours 1445 Minutes". What I would like for it to do is only return 1 Day 5 Minutes. Is it possible to link all three of the _datediff() together to so it will return an exact amount? [script Attached]

Updated Script

#include <GUIConstants.au3>
#include <GuiEdit.au3>
#include <Date.au3>
GUICreate ( "Jail Credit Time Calculator", 275, 250, -1, -1 )
GUISetState () 

$menu = GuiCtrlCreateMenu ("Menu")
$aboutitem = GuiCtrlCreateMenuitem ("About",$menu)
$closeitem = GuiCtrlCreateMenuitem ("Close",$menu)
$menuspacer = GuiCtrlCreateMenu ( "                                               " )
$menudate= GUICtrlCreateMenu( @MON & "/" & @MDAY & "/" &@YEAR )


GUICtrlCreateGroup("Booking Date and Time", 5, 5, 125, 95)
GUICtrlCreateLabel ("YYYY/MM/DD HH:MM", 15, 20)
$bookdate= GUICtrlCreateInput ( "", 10, 50, 100, 20 ); booking date
GUICtrlCreateGroup("Release Date and Time", 145, 5, 125, 95)
GUICtrlCreateLabel ("YYYY/MM/DD HH:MM", 155, 20)
$releasedate= GUICtrlCreateInput ( "", 150, 50, 100, 20 ); release date/time

GUICtrlSetLimit ( $bookdate, 20, 20 )
GUICtrlSetLimit ( $releasedate, 20, 20 )

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


GUICtrlCreateGroup("Credit Time", 23, 160, 230, 65)
$result= GUICtrlCreateInput ( "Credit Time", 30, 175, 215, 40 )

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

        $bd= GUICtrlRead ( $bookdate ) 
        $rd= GUICtrlRead ( $releasedate ) 
        
          GUICtrlSetData( $result, _DateDiff( 'D', $bd, $rd) & " " & "Days" & " " & _DateDiff( 'h', $bd, $rd) & " " & "Hours" & " "& _DateDiff( 'n', $bd, $rd) & " " & "Minutes" )
       case $msg= $reset
            guictrlsetdata( $bookdate, "" )
            guictrlsetdata( $releasedate, "" )
            

        case $msg= $close
           Exit
               Case $msg = $aboutitem
            Msgbox(0, "About", "Credit Time Calculator" & @crlf & @crlf & "Created by Jeremy Brice" & @CRlf & @crlf &  "Version 1.3 Build 4509" & @CRlf & "Copyright© 2008")
            Case $msg = $closeitem
            Exit
    Exit
EndSelect
WEnd

"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

_DateAdd() wasn't exaclty what I was looking for in this situation, but I will definitely be using it for the next portion of my script. However, you pointing it out did lead me to _DateDiff(). I have updated the script to use _DateDiff(), however Is it possible to have it return an exact value? What I mean is, if I put in a booking date of 2008/5/12 5:15 and a release date of 2008/5/13 5:20. With my current script it returns the following "1 Days 24 Hours 1445 Minutes". What I would like for it to do is only return 1 Day 5 Minutes. Is it possible to link all three of the _datediff() together to so it will return an exact amount?

This seems to give a correct answer. I haven't fully tested it.

#include <Date.au3>
$sBkTime = "2008/01/01 01:00:00"
$sRelTime = "2008/02/01 02:15:00"

$iDateCalcD = _DateDiff('D', $sBkTime, $sRelTime)
$iDateCalch = _DateDiff('h', $sBkTime, $sRelTime)
$iDateCalcm = _DateDiff('n', $sBkTime, $sRelTime)
MsgBox(4096, "", "Time difference  " & $iDateCalcD & " Days " & Int($iDateCalch - $iDateCalcD * 24) & " hr " & _
        Int($iDateCalcm - $iDateCalch * 60) & "min")
Edited by Malkey
Link to comment
Share on other sites

Pain and Malkey I want to thank you very much for your help. Pain for guiding me in the right direction, and Malkey for helping me with finishing it up. My hats off to both of you! :P

"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...