He hecho un pequeño GUI que utiliza la rutina anterior (esta vez convertida en función), así es más "divertido" de manejar.
El original por defecto nada más abrirse me dice la edad exacta que tengo, pero para colgarlo aquí pongo, como arriba, la edad de AutoIt v3, creo que es lo propio
Código: Seleccionar todo
#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <Date.au3>
Opt('MustDeclareVars', 1)
Global $DTM_SETFORMAT_ = 0x1032, $estilo = "yyyy/MM/dd"
Global $date1, $date2, $fIni, $fFin, $etqTiempo, $etqOrden, $btnCerrar
$fIni = "2004/02/29" ;AutoIt v3, día cero
$fFin = _NowCalc()
GUICreate("Diferencia Fechas", 230, 150)
GUICtrlCreateLabel("Fecha Inicial:", 10, 10, 200)
$date1 = GUICtrlCreateDate($fIni, 10, 25, 100, 20)
GUICtrlSendMsg($date1, $DTM_SETFORMAT_, 0, $estilo)
GUICtrlCreateLabel("Fecha Final:", 120, 10, 200)
$date2 = GUICtrlCreateDate($fFin, 120, 25, 100, 20)
GUICtrlSendMsg($date2, $DTM_SETFORMAT_, 0, $estilo)
_DifFechasStr($fIni, $fFin)
$etqOrden = GUICtrlCreateLabel("Han pasado:", 10, 60, 200)
GUICtrlSetFont(-1, 10, 800)
$etqTiempo = GUICtrlCreateLabel(_DifFechasStr($fIni, $fFin), 10, 80, 200)
GUICtrlSetFont(-1, 10, 800)
$btnCerrar = GUICtrlCreateButton("&Cerrar", 85, 110, 60, 25)
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $btnCerrar
Exit
Case $date1, $date2
GuiCtrlSetData($etqTiempo, _DifFechasStr(GuiCtrlRead($date1), GuiCtrlRead($date2)))
EndSwitch
WEnd
Func _DiferenciaFechas($fIni, $fFin, ByRef $anyos, ByRef $meses, ByRef $dias)
Local $ftemp
$anyos = _DateDiff("y", $fIni, $fFin)
$ftemp = _DateAdd("y", $anyos, $fIni)
$meses = _DateDiff("m", $ftemp, $fFin)
$ftemp = _DateAdd("m", $meses, $ftemp)
$dias = _DateDiff("d", $ftemp, $fFin)
EndFunc
Func _DifFechasStr($fInicial, $fFinal)
Local $anyos, $meses, $dias, $temp = ""
If $fInicial > $fFinal Then
Local $temp = $fInicial
$fInicial = $fFinal
$fFinal = $temp
GuiCtrlSetData($etqOrden, "Faltan:")
Else
GuiCtrlSetData($etqOrden, "Han pasado:")
EndIf
_DiferenciaFechas($fInicial, $fFinal, $anyos, $meses, $dias)
Return StringFormat("%d años, %d meses, %d días", $anyos, $meses, $dias)
EndFunc