Jump to content
Sign in to follow this  
gseller

Quickly find the difference between Two dates and times

Recommended Posts

gseller

I know it is not the first.. Just my take on it.. Thought someone might get something out of it...

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         myName

 Script Function:
 Template AutoIt script.

#ce ----------------------------------------------------------------------------


#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <Date.au3>

#Region ### START Koda GUI section ### Form=C:\time-difference.kxf
$hGUI = GUICreate("Time/Date Diference", 280, 250, 192, 124)

$menu = GuiCtrlCreateMenu ("Menu")
$aboutitem = GuiCtrlCreateMenuitem ("About",$menu)
$closeitem = GuiCtrlCreateMenuitem ("Close",$menu)

$Combo2 = GUICtrlCreateCombo(@Hour, 8, 68, 49, 25)
GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
$Combo3 = GUICtrlCreateCombo(@Min, 60, 68, 57, 25)
GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59")
$Date1 = GUICtrlCreateDate("", 16, 25, 90, 21)
 $DTM_SETFORMAT_ = 0x1032
 $style = "yyyy/MM/dd"
 GUICtrlSendMsg($Date1, $DTM_SETFORMAT_, 0, $style)
$Date2 = GUICtrlCreateDate("", 170, 25, 90, 21)
 $DTM_SETFORMAT_ = 0x1032
 $style = "yyyy/MM/dd"
 GUICtrlSendMsg($Date2, $DTM_SETFORMAT_, 0, $style)
$Combo1 = GUICtrlCreateCombo(@Hour, 165, 68, 49, 25)
GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
$Combo4 = GUICtrlCreateCombo(@Min, 217, 68, 57, 25)
GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59")
$Label1 = GUICtrlCreateLabel("Ending Date:", 175, 5, 104, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$Label2 = GUICtrlCreateLabel("Beginning Date:", 12, 5, 128, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$Label3 = GUICtrlCreateLabel("Hr:", 18, 48, 28, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$Label4 = GUICtrlCreateLabel("Min:", 75, 48, 37, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$Label5 = GUICtrlCreateLabel("Hr:", 180, 48, 28, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$Label6 = GUICtrlCreateLabel("Min:", 230, 48, 37, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
GUICtrlCreateGroup("Credit Time", 23, 100, 230, 65)
$result= GUICtrlCreateInput ( "Date/Time Difference", 30, 115, 215, 40 )


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

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $calculate
   $bd= ( GUICtrlRead($Date1) & " " & GUICtrlRead($Combo2) & ":" & GUICtrlRead($Combo3) ) 
   $rd= ( GUICtrlRead($Date2) & " " & GUICtrlRead($Combo1) & ":" & GUICtrlRead($Combo4) ) 
   
   $iDateCalcD = _DateDiff('D', $bd, $rd)
   $iDateCalch = _DateDiff('h', $bd, $rd)
   $iDateCalcm = _DateDiff('n', $bd, $rd)
  
    GUICtrlSetData( $result, $iDateCalcD & " Days " & Int($iDateCalch - $iDateCalcD * 24) & " hr " & Int($iDateCalcm - $iDateCalch * 60) & "min" )
    sleep(250)
     Case $reset
   guictrlsetdata( $Combo1, @Hour )
   guictrlsetdata( $Combo2, @Hour )
   guictrlsetdata( $Combo3, @Min )
   guictrlsetdata( $Combo4, @Min )
   guictrlsetdata( $result, "0 Days 0 hr 0min" )
   guictrlsetdata( $Date1, "" )
   guictrlsetdata( $Date2, "" )

  Case $close
     Exit
  Case $aboutitem
   Msgbox(0, "About", "Time/Date Diference" & @crlf & @crlf & "Quickly find the difference" & @CRlf & @crlf &  "between Two dates and times")
  Case $closeitem
   Exit
 Exit
 EndSwitch
WEnd

edit: updated code per post #2

Enjoy!

Edited by gseller

Share this post


Link to post
Share on other sites
Valuater

nice idea as a gui...

small error

GUICtrlCreateMenu( @MON & "/" & @MDAY & "/" &@YEAR )

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
gseller

Sorry, I am not sure how that happened.. in my code it shows as

$menudate= GUICtrlCreateMenu( @MON & "/" & @MDAY & "/" &@YEAR )

but it can be removed along with

$menuspacer = GuiCtrlCreateMenu ( " " )

as these are not really used...

Thank You for your feedback :)

edit: the forum is adding the [email &

Edited by gseller

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  

×