Jump to content

time difference


Recommended Posts

i need a good func for

$starttime=GUICtrlCreateDate("", -1, -1, -1, -1, $DTS_TIMEFORMAT)
$endtime=GUICtrlCreateDate("", -1, -1, -1, -1, $DTS_TIMEFORMAT)
_GUICTRLDTP_SETFORMAT($starttime, "hh:mm tt")
_GUICTRLDTP_SETFORMAT($endtime, "hh:mm tt")
$totaltime=GUICtrlRead($endtime)-GUICtrlRead($starttime)

i just need to figure out the time diffrence but i need it to work with am/pm. thanks.

Link to comment
Share on other sites

Link to comment
Share on other sites

im probably looking into this wrong, but im not sure how.

#Include <GUIConstantsEX.au3>
#Include <ComboConstants.au3>
#Include <EditConstants.au3>
#Include <Date.au3>
#Include <DateTimeConstants.au3>
#Include <GuiDateTimePicker.au3>

Global $gui1 = GUICreate("redLabel worklog", 350, 450)
    GUICtrlCreateLabel("company", 25, 25)
    $tCompany = GUICtrlCreateCombo("all", 25, 40, 50, DEFAULT, $CBS_DROPDOWNLIST)
        GUICtrlSetData(-1, "AEC")
        GUICtrlSetData(-1, "AMS")
        GUICtrlSetData(-1, "CW")
        GUICtrlSetData(-1, "DTA")
        GUICtrlSetData(-1, "MF")
    GUICtrlCreateLabel("user assisted (if applicable)", 125, 25)
    $tUser = GUICtrlCreateInput("", 125, 40, 200)
    GUICtrlCreateLabel("date", 25, 85)
    $tDate = GUICtrlCreateMonthCal("", 25, 100, 220, 175)
    GUICtrlCreateLabel("start time", 255, 115)
    $tStartTime = GUICtrlGetHandle(GUICtrlCreateDate("", 255, 130, 70, -1, $DTS_TIMEFORMAT))
    GUICtrlCreateLabel("end time", 255, 165)
    $tEndTime = GUICtrlGetHandle(GUICtrlCreateDate("", 255, 180, 70, -1, $DTS_TIMEFORMAT))
    GUICtrlCreateLabel("time spent", 255, 215, 50)
    $tTT = _DateDiff('h', $tStartTime, $tEndTime)
    $tTotalTime = GUICtrlCreateInput("", 255, 230, 70)
        GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlCreateLabel("task(s) performed", 25, 300)
    $tTask = GUICtrlCreateInput("", 25, 315, 300, 50)
    $tViewLog = GUICtrlCreateButton("&open log", 25, 400, 75)
    $tEmailLog = GUICtrlCreateButton("&email log", 100, 400, 75)
    $tCancel = GUICtrlCreateButton("&cancel <", 175, 400, 75)
    $tLogEntry = GUICtrlCreateButton("&log entry >", 250, 400, 75)
    GUISetState()
    _GUICTRLDTP_SETFORMAT($tStartTime, "hh:mm tt")
    _GUICTRLDTP_SETFORMAT($tEndTime, "hh:mm tt")
    
While 1
    $msg1 = GUIGetMsg()
    Switch $msg1
        Case $tEndTime
            GUICtrlSetData($tTotalTime, $tTT)
        Case $GUI_EVENT_CLOSE, $tCancel
            EXIT
        Case $tViewLog
            ShellExecute(@SCRIPTDIR &"\worklog2010.txt")
        Case $tEmailLog
            _tEmailLog()
    EndSwitch
Wend

    Func _tEmailLog()
        Local $gui2 = GUICREATE("redLabel worklog", 250, 200)
        GUICtrlCreateLabel("select date range to attach to email", 25, 25)
        GUICtrlCreateLabel("start date", 25, 50)
        $tStartDate = GUICtrlCreateDate("", 25, 65, 200)
        GUICtrlCreateLabel("end date", 25, 100)
        $tEndDate = GUICtrlCreateDate("", 25, 115, 200)
        $tCancelAttachLog = GUICtrlCreateButton("&cancel <", 75, 150, 75)
        $tAttachLog = GUICtrlCreateButton("&attach >", 150, 150, 75)
        GUISetState()
        GUISwitch($gui2)
        While 1
            $msg2 = GUIGetMsg()
            Switch $msg2
            Case $GUI_EVENT_CLOSE, $tCancelAttachLog
                GUIDelete()
                GUISwitch($gui1)
                Return
            Case $tAttachLog
                GUISetState(@SW_HIDE)
            EndSwitch
        WEND
    EndFunc

its not updating the $tTotalTime inputbox.

Edited by redLabel
Link to comment
Share on other sites

You are sending _Datediff() 2 handles which is not going to work. Also that fuction requires date and time. Ill take a closer look. get back to ya in a bit.

Link to comment
Share on other sites

Ok take a look at this. Func _24Hour turns your AM PM time back to 24 hour so you can use it with _DateDiff(). I swear there was a function that did this already but maybe not. I also made _Datediff() return seconds so then you can calc hours and mins.

#Include <GUIConstantsEX.au3>
#Include <ComboConstants.au3>
#Include <EditConstants.au3>
#Include <Date.au3>
#Include <DateTimeConstants.au3>
#Include <GuiDateTimePicker.au3>

Global $gui1 = GUICreate("redLabel worklog", 350, 450)
    GUICtrlCreateLabel("company", 25, 25)
    $tCompany = GUICtrlCreateCombo("all", 25, 40, 50, DEFAULT, $CBS_DROPDOWNLIST)
        GUICtrlSetData(-1, "AEC")
        GUICtrlSetData(-1, "AMS")
        GUICtrlSetData(-1, "CW")
        GUICtrlSetData(-1, "DTA")
        GUICtrlSetData(-1, "MF")
    GUICtrlCreateLabel("user assisted (if applicable)", 125, 25)
    $tUser = GUICtrlCreateInput("", 125, 40, 200)
    GUICtrlCreateLabel("date", 25, 85)
    $tDate = GUICtrlCreateMonthCal("", 25, 100, 220, 175)
    GUICtrlCreateLabel("start time", 255, 115)
    $tStartTime = GUICtrlCreateDate("", 255, 130, 70, -1, $DTS_TIMEFORMAT)
    GUICtrlCreateLabel("end time", 255, 165)
    $tEndTime = GUICtrlCreateDate("", 255, 180, 70, -1, $DTS_TIMEFORMAT)
    GUICtrlCreateLabel("time spent", 255, 215, 50)
    $tTotalTime = GUICtrlCreateInput("", 255, 230, 70)
        GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlCreateLabel("task(s) performed", 25, 300)
    $tTask = GUICtrlCreateInput("", 25, 315, 300, 50)
    $tViewLog = GUICtrlCreateButton("&open log", 25, 400, 75)
    $tEmailLog = GUICtrlCreateButton("&email log", 100, 400, 75)
    $tCancel = GUICtrlCreateButton("&cancel <", 175, 400, 75)
    $tLogEntry = GUICtrlCreateButton("&log entry >", 250, 400, 75)
    GUISetState()
    _GUICTRLDTP_SETFORMAT(GUICtrlGetHandle($tStartTime), "hh:mm tt")
    _GUICTRLDTP_SETFORMAT(GUICtrlGetHandle($tEndTime), "hh:mm tt")

While 1
    $msg1 = GUIGetMsg()
    Switch $msg1
        Case $tEndTime
            $sDate = '2010/01/01 '; Put Date here
            $tTT = _DateDiff('h', $sDate & _24Hour(GUICtrlRead($tStartTime)), $sDate & _24Hour(GUICtrlRead($tEndTime)))
            GUICtrlSetData($tTotalTime, $tTT)
        Case $GUI_EVENT_CLOSE, $tCancel
            EXIT
        Case $tViewLog
            ShellExecute(@SCRIPTDIR &"\worklog2010.txt")
        Case $tEmailLog
            _tEmailLog()
    EndSwitch
Wend

Func _24Hour($Time)
    Local $New_Time, $PM = False
    If StringInStr($Time, 'PM') Then $PM = True
    $Time = StringLeft($Time, 5)
    $Hour = Number(StringLeft($Time, 2))
    $Min = Number(StringTrimLeft($Time, 3))
    If $PM Then $Hour += 12
    Return $Hour & ':' & $Min & ':00'
EndFunc

    Func _tEmailLog()
        Local $gui2 = GUICREATE("redLabel worklog", 250, 200)
        GUICtrlCreateLabel("select date range to attach to email", 25, 25)
        GUICtrlCreateLabel("start date", 25, 50)
        $tStartDate = GUICtrlCreateDate("", 25, 65, 200)
        GUICtrlCreateLabel("end date", 25, 100)
        $tEndDate = GUICtrlCreateDate("", 25, 115, 200)
        $tCancelAttachLog = GUICtrlCreateButton("&cancel <", 75, 150, 75)
        $tAttachLog = GUICtrlCreateButton("&attach >", 150, 150, 75)
        GUISetState()
        GUISwitch($gui2)
        While 1
            $msg2 = GUIGetMsg()
            Switch $msg2
            Case $GUI_EVENT_CLOSE, $tCancelAttachLog
                GUIDelete()
                GUISwitch($gui1)
                Return
            Case $tAttachLog
                GUISetState(@SW_HIDE)
            EndSwitch
        WEND
    EndFunc
Link to comment
Share on other sites

Hi, I've had many problems with dates...Maybe some of these functions will help you

1) Change from 24 hours to AM/PM

func Formatdate($start) ; Format time for calendar
$h=StringMid($start,9,2)
$min=StringMid($start,11,2)
if $h<10 then $h= stringright($h,1)
If $h > 12 Then
    $h = $h - 12
    $min = $min & " PM"
ElseIf $h = 12 Then
    $min = $min & " PM"
Else
    $min = $min & " AM"
EndIf
$time=$h&":"&$min
if $time="0:00 AM" then $time="All Day Event"
Return $time
EndFunc

2)Change from 12 to 24

func twelveto24($time)
    if StringRight($time,2)="am" then
        if number(StringLeft($time,2))>9 Then
            $time=StringLeft($time,5)
        Else
            $time="0"&StringLeft($time,4)
        EndIf
    Else
        $tempnumb=Number(stringleft($time,2))+12
        if number(StringLeft($time,2))>9 Then
            $time=$tempnumb&Stringmid($time,3,3)
        Else
            $time=$tempnumb&Stringmid($time,2,3)
        EndIf
    EndIf
Return $time
EndFunc

3)letter date to number date (may need to change "-" to "/")

func datetonum($string)

if StringInStr($string,"January") then $mon=01
if StringInStr($string,"February") then $mon=02
if StringInStr($string,"March") then $mon=03
if StringInStr($string,"April") then $mon=04
if StringInStr($string,"May") then $mon=05
if StringInStr($string,"June") then $mon=06
if StringInStr($string,"July") then $mon=07
if StringInStr($string,"August") then $mon=08
if StringInStr($string,"September") then $mon=09
if StringInStr($string,"October") then $mon=10
if StringInStr($string,"November") then $mon=11
if StringInStr($string,"Decenber") then $mon=12
    
if StringMid($string,stringinstr($string,",")-2,1)=" " then
    $days ="0"&StringMid($string,stringinstr($string,",")-1,1)
Else
    $days =StringMid($string,stringinstr($string,",")-2,2)
EndIf

$years=StringRight($string,4)
if Number($mon)>9 then $returnvar=($years&"-"&$mon&"-"&$days)
if Number($mon)<10 then $returnvar=($years&"-0"&$mon&"-"&$days)
Return $returnvar
EndFunc
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...