Sign in to follow this  
Followers 0
Necromorph

_DateDiff

8 posts in this topic

okay, here is what i got

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

GUICreate("test", 500, 500)
GUISetState()
    $labelStartTime = GUICtrlCreateLabel("start time", 265, 110.5)
    $timeStartTime = GUICtrlGetHandle(GUICtrlCreateDate("", 265, 133, 90, -1, $DTS_TIMEFORMAT))
        _GUICtrlDTP_SetFormat($timeStartTime, "hh:mm:ss  tt")
    $labelEndTime = GUICtrlCreateLabel("end time", 265, 175)
    $timeEndTime = GUICtrlGetHandle(GUICtrlCreateDate("", 265, 197.5, 90, -1, $DTS_TIMEFORMAT))
        _GUICtrlDTP_SetFormat($timeEndTime, "hh:mm:ss  tt")
    $labelTotalTime = GUICtrlCreateLabel("total time", 265, 242.5)
    $timeTotalTime = GUICtrlCreateInput("", 265, 265, 90, -1, $ES_READONLY)
        $varTotalTime = _DateDiff('n', _NowCalcDate() & "" & GUICtrlRead($timeStartTime), _NowCalcDate() & "" & GUICtrlRead($timeEndTime))
        $buttonCalcTotalTime = GUICtrlCreateButton("calc time", 25, 400, 75

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE, $buttonCancelForm
            Exit
        Case $buttonCalcTotalTime
            GUICtrlSetData($timeTotalTime, $varTotalTime)
        Case $buttonLogEntry
    EndSwitch
WEnd

but in the second case, to calculate the time diff i keep getting a "0" in my total time box, could it be because of the "GUICtrlGetHandle" in there, im just not sure what im doing wrong here. thanks for the help

Share this post


Link to post
Share on other sites



@Redlabel,

To calculate the difference you need the complete date year/month/day hour:min:sec

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

Dim $buttonCancelForm, $buttonLogEntry

GUICreate("test", 500, 500)

    $labelStartTime = GUICtrlCreateLabel("start time", 265, 110.5)
    $timeStartTime = GUICtrlCreateDate("", 265, 133, 90, -1, $DTS_TIMEFORMAT)
        _GUICtrlDTP_SetFormat($timeStartTime, "hh:mm:ss  tt")
    $labelEndTime = GUICtrlCreateLabel("end time", 265, 175)
    $timeEndTime = GUICtrlCreateDate("", 265, 197.5, 90, -1, $DTS_TIMEFORMAT)
        _GUICtrlDTP_SetFormat($timeEndTime, "hh:mm:ss  tt")
    $labelTotalTime = GUICtrlCreateLabel("total time", 265, 242.5)
    $timeTotalTime = GUICtrlCreateInput("", 265, 265, 90, -1, $ES_READONLY)
    $buttonCalcTotalTime = GUICtrlCreateButton("calc time", 25, 400, 75)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            Exit
        Case -100 To 0
            ContinueLoop
        Case $GUI_EVENT_CLOSE
            Exit
        Case $buttonCancelForm
            Exit
        Case $buttonCalcTotalTime
            MsgBox(0, "start", @YEAR & "/" & @MON & "/" & @YDAY & " " & GUICtrlRead($timeStartTime))
            MsgBox(0, "end", @YEAR & "/" & @MON & "/" & @YDAY & " " & GUICtrlRead($timeEndTime))
            $varTotalTime = _DateDiff('n', @YEAR & "/" & @MON & "/" & @MDAY & " " & GUICtrlRead($timeStartTime),@YEAR & "/" & @MON & "/" & @MDAY & " " & GUICtrlRead($timeEndTime))
            GUICtrlSetData($timeTotalTime, $varTotalTime)
        Case $buttonLogEntry
    EndSwitch
WEnd

Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites

thanks for your reply, but it still doesn't work, but i know why

i use, in place of @YEAR & "/" & @MDAY & "/" .... and so on

the _NowCalcDate returns the same value, YYYY/MM/DD

so the problem is that the GUICtrlRead($timeStartTime) doesn't work,because im using this:

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE, $buttonCancelForm
            Exit
        Case $buttonCalcTotalTime
            MsgBox(0, "redLabel timeKeeper", _NowCalcDate() & " " & GUICtrlRead($timeStartTime))
            MsgBox(0, "redLabel timeKeeper", _NowCalcDate() & " " & GuiCtrlRead($timeEndTime))
            $varTotalTime = _DateDiff('n', _NowCalcDate() & " " & GUICtrlRead($timeStartTime), _NowCalcDate() & " " & GUICtrlRead($timeEndTime))        
            GUICtrlSetData($timeTotalTime, $varTotalTime)
        Case $buttonNewUser
        Case $buttonDeleteUser
        Case $buttonLogEntry
    EndSwitch
WEnd

but when i get the MsgBox() it returns this "2010/03/28 0". so the problem is i need a way to read the time, which GUICtrlRead doesnt do for this, and in the Help Doc it says that for a DateCtrl, it returns the Date, so that maybe the issue. thanks for your help though.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

RedLabel

Even when i use _NowCalcDate () my example works.

I do not use -> GUICtrlGetHandle. Your complete example in your first post does not work.

If you post your original code i could help you better..

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

Dim $buttonCancelForm, $buttonLogEntry

GUICreate("test", 500, 500)

    $labelStartTime = GUICtrlCreateLabel("start time", 265, 110.5)
    $timeStartTime = GUICtrlCreateDate("", 265, 133, 90, -1, $DTS_TIMEFORMAT)
        _GUICtrlDTP_SetFormat($timeStartTime, "hh:mm:ss  tt")
    $labelEndTime = GUICtrlCreateLabel("end time", 265, 175)
    $timeEndTime = GUICtrlCreateDate("", 265, 197.5, 90, -1, $DTS_TIMEFORMAT)
        _GUICtrlDTP_SetFormat($timeEndTime, "hh:mm:ss  tt")
    $labelTotalTime = GUICtrlCreateLabel("total time", 265, 242.5)
    $timeTotalTime = GUICtrlCreateInput("", 265, 265, 90, -1, $ES_READONLY)
    $buttonCalcTotalTime = GUICtrlCreateButton("calc time", 25, 400, 75)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            Exit
        Case -100 To 0
            ContinueLoop
        Case $GUI_EVENT_CLOSE
            Exit
        Case $buttonCancelForm
            Exit
        Case $buttonCalcTotalTime
            $varTotalTime = _DateDiff('n', _NowCalcDate() & " " & GUICtrlRead($timeStartTime), _NowCalcDate() & " " & GUICtrlRead($timeEndTime))
            GUICtrlSetData($timeTotalTime, $varTotalTime)
        Case $buttonLogEntry
    EndSwitch
WEnd
Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

i figured it out, in my script im using it like this

$timeStartTime = GUICtrlGetHandle(GUICtrlCreateDate("", 265, 133, 90, -1, $DTS_TIMEFORMAT))
     _GUICtrlDTP_SetFormat($timeStartTime, "hh:mm  tt")

you have to use the GUICtrlGetHandle to set the format, but if i do it like this

$timeStartTime = GUICtrlCreateDate("", 265, 133, 90, -1, $DTS_TIMEFORMAT)
     $formatStartTime = GUICtrlGetHandle($timeStartTime)
     _GUICtrlDTP_SetFormat($formatStartTime, "hh:mm  tt")

it works. thanks for all your help.

Edited by redLabel

Share this post


Link to post
Share on other sites

okay, here is one step further, do you know a func that would make it so i can round an hour to a min it this

example

start time: 4:00 pm

end time: 5:15 pm

total time: 1.25

i need to find the _datediff in hours, but make it round it 2 decimal places. just wondering if there is a built in func or if i need to attepmt to make my own.

Share this post


Link to post
Share on other sites

Hi,

I think you have to create one yourself, but below is an example to calculate "Uptime [ww:dd:hh:mm:ss]"

Dim $UptimeArray = _Uptime()

Func _Uptime()
    Local $iSubTotal = DllCall("WinMM.dll", "long", "timeGetTime")
    ;local $iSubTotal = DllCall('kernel32.dll', 'int', 'GetTickCount')

    If Not IsArray($iSubTotal) Then Return SetError(1, 0, 0)
    $iSubTotal = $iSubTotal[0] / 1000
    Local $iWeek = Int(($iSubTotal / 604800))
    If $iWeek > 0 Then $iSubTotal -= $iWeek * 604800
    Local $iDay = Int(($iSubTotal / 86400))
    If $iDay > 0 Then $iSubTotal -= $iDay * 86400
    Local $iHour = Int(($iSubTotal / 3600))
    Local $iMin = Int(($iSubTotal - ($iHour * 3600)) / 60)
    Local $iSec = Int(($iSubTotal - $iHour * 3600) - ($iMin * 60))
    Return StringSplit(StringFormat('%02d', $iWeek) & ':' & StringFormat('%02d', $iDay) & ':' & StringFormat('%02d', $iHour) & ':' & _
            StringFormat('%02d', $iMin) & ':' & StringFormat('%02d', $iSec), ':')
EndFunc   ;==>_Uptime

Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites

Seems like there would be an easier way, like

#include <Date.au3>

$varTotalTime = _Date_Time_SomethingtoStr($totalTime)

$setTotalTime = Round($varTotalTime)

GUICtrlSetData($totalTime, $setTotalTime)

Im still looking.

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  
Followers 0