;~ AutoIt Version: 3.3.14.5
#include <GUIConstants.au3>
#include <GuiDateTimePicker.au3>
#include <WinAPIConv.au3>
#include <Date.au3>
Global $g_idDate1, $g_idDate2, $g_idCmbType, $g_idInpDiff
Example()
Func Example()
GUICreate(@ScriptName, 410, 90)
$g_idDate1 = GUICtrlCreateDate("2000/01/01 00:00:00", 10, 10, 390, 20)
GUICtrlSendMsg(-1, $DTM_SETFORMATW, 0, "dd.MM.yyyy | HH:mm:ss")
$g_idDate2 = GUICtrlCreateDate("", 10, 35, 390, 20)
GUICtrlSendMsg(-1, $DTM_SETFORMATW, 0, "dd.MM.yyyy | HH:mm:ss")
$g_idCmbType = GUICtrlCreateCombo("", 10, 60, 90, 20, BitOR($CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_DROPDOWNLIST))
GUICtrlSetData(-1, "В днях|В месяцах|В годах|В неделях|В часах|В минутах|В секундах", "В годах")
$g_idInpDiff = GUICtrlCreateInput("", 105, 60, 295, 20, BitOR($GUI_SS_DEFAULT_INPUT, $ES_READONLY))
GUIRegisterMsg($WM_NOTIFY, WM_PROC)
GUIRegisterMsg($WM_COMMAND, WM_PROC)
GUISetState()
_ShowDiff()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>Example
Func WM_PROC($hWnd, $iMsg, $wParam, $lParam)
Switch $iMsg
Case $WM_NOTIFY
Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
Switch DllStructGetData($tNMHDR, "IDFrom")
Case $g_idDate1, $g_idDate2
Switch DllStructGetData($tNMHDR, "Code")
Case $DTN_DATETIMECHANGE
_ShowDiff()
EndSwitch
EndSwitch
Case $WM_COMMAND
Switch _WinAPI_LoWord($wParam)
Case $g_idCmbType
Switch _WinAPI_HiWord($wParam)
Case $CBN_SELCHANGE
_ShowDiff()
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_PROC
Func _ShowDiff()
Local $sType
Switch GUICtrlRead($g_idCmbType)
Case "В днях"
$sType = "D"
Case "В месяцах"
$sType = "M"
Case "В годах"
$sType = "Y"
Case "В неделях"
$sType = "w"
Case "В часах"
$sType = "h"
Case "В минутах"
$sType = "n"
Case "В секундах"
$sType = "s"
EndSwitch
Local $iDiff = _DateDiff($sType, _GUICtrlDTP_GetFormatTime($g_idDate1), _GUICtrlDTP_GetFormatTime($g_idDate2))
GUICtrlSetData($g_idInpDiff, $iDiff)
EndFunc ;==>_ShowDiff
Func _GUICtrlDTP_GetFormatTime($hDTP)
If Not IsHWnd($hDTP) Then $hDTP = GUICtrlGetHandle($hDTP)
Local $aDate = _GUICtrlDTP_GetSystemTime($hDTP)
Return StringFormat("%04i/%02i/%02i %02i:%02i:%02i", $aDate[0], $aDate[1], $aDate[2], $aDate[3], $aDate[4], $aDate[5])
EndFunc ;==>_GUICtrlDTP_GetFormatTime