Sign in to follow this  
Followers 0
Rawox

[UPDATED] Months Problem

6 posts in this topic

#1 ·  Posted (edited)

Hi,

I'm makin a script that calculates the different between two times.

I'm almost done... but I don't know how to do the months because months have different digits. (31, 30, 29, 28)... I tried it with _Date_Time_GetSystemTime () & _Date_Time_SystemTimeToDateTimeStr, _DateDiff and _DateDaysInMonth but I just can't figure it out :D

Even my dad can't fix it :D

#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
$i = 0
$Top = 12
$Length = 130
$Height = 11
$Extraleft = 68
$sDate = "2008/11/23 18:00:00"
$x = 0
$h = 1 ;hours
$D = 1 ;Days
$M = 1 ;Months
$Y = 1 ;Years
HotKeySet ( "{ESC}", "ExitProg" )
;AdlibEnable ( "refresh", 5000 )
;////////////////////////////////////////////////////////////////////// BASE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\;
$iDateCalcseconds    = _DateDiff ( 's',"2008/11/23 18:00:00", _NowCalc ( ) )
$iDateCalcminutes    = _DateDiff ( 'n',"2008/11/23 18:00:00", _NowCalc ( ) )
$iDateCalchours      = _DateDiff ( 'h',"2008/11/23 18:00:00", _NowCalc ( ) )
$iDateCalcdays       = _DateDiff ( 'D',"2008/11/23 18:00:00", _NowCalc ( ) )
$iDateCalcweeks      = _DateDiff ( 'w',"2008/11/23 18:00:00", _NowCalc ( ) )
$iDateCalcmonths     = _DateDiff ( 'M',"2008/11/23 18:00:00", _NowCalc ( ) )
$iDateCalcyears      = _DateDiff ( 'Y',"2008/11/23 18:00:00", _NowCalc ( ) )
;////////////////////////////////////////////////////////////////////// BASE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\;
$GUI     = GUICreate ( "Cas (L) Lizzy", 270, 218+50, @DesktopWidth/2-139, @DesktopHeight/2-145 )
$Copy    = GUICtrlCreateButton ( "Copy", 190, 8, 70, 22 )
$ACopy   = GUICtrlCreateButton ( "Copy...", 10, 188, 100, 22 )
$Refresh = GUICtrlCreateButton ( "Refresh", 110, 188, 75, 22 )
$Quit    = GUICtrlCreateButton ( "Quit", 185, 188, 75, 22 )
$Year    = GUICtrlCreateLabel ( "00", 11+$Extraleft, $Top, 22 )
$Month   = GUICtrlCreateLabel ( "00", 33+$Extraleft, $Top, 22 )
$Day     = GUICtrlCreateLabel ( "00", 54+$Extraleft, $Top, 22 )
$Hour    = GUICtrlCreateLabel ( "00", 82+$Extraleft, $Top, 22 )
$Minute  = GUICtrlCreateLabel ( "00", 99+$Extraleft, $Top, 22 )
;///////////////////////////////////////////////////////////////// COMPILED TIME \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\;
$GetMinutes = _DateDiff ( "n", $sDate, _NowCalc ( ) )
GUICtrlSetData ( $Minute, $GetMinutes )
Do
    If GUICtrlRead ( $Minute ) > 60 Then
        GUICtrlSetData ( $Hour, $h )
        $h += 1
        $n = GUICtrlRead ( $Minute )
        GUICtrlSetData ( $Minute, $n-60 )
    EndIf
Until GUICtrlRead ( $Minute ) > 0 And GUICtrlRead ( $Minute ) < 60
Do
    If GUICtrlRead ( $Hour ) > 24 Then
        GUICtrlSetData ( $Day, $D )
        $D += 1
        $h = GUICtrlRead ( $Hour )
        GUICtrlSetData ( $Hour, $h-24 )
    EndIf
Until GUICtrlRead ( $Hour ) > 0 And GUICtrlRead ( $Hour ) < 24
GUISetState ( @SW_SHOW )

;Do ==> MY 100st TRY OR SOMETHIN LIKE THAT
;   $DaysinMonth = _DateDaysInMonth ( @YEAR, @MON-$x )
;   MsgBox ( 0, "lol", $DaysinMonth )
;   $x += 1
;Until 1 = 2 ;GUICtrlRead ( $Day ) > 0 And GUICtrlRead ( $Day ) < $DaysinMonth 

;////////////////////////////////////////////////////////////////////// GUI \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\;
GUISetState ( @SW_SHOW )
GUISetFont ( 14, 400 )
GUICtrlCreateLabel ( "/", 26+$Extraleft, 8, 5 )
GUICtrlCreateLabel ( "/", 47+$Extraleft, 8, 5 )
GUISetFont ( 12, 400 )
GUICtrlCreateLabel ( "-", 72+$Extraleft, 7, 5 )
GUISetFont ( 8.5, 400 )
GUICtrlCreateLabel ( "Together for:", 12, 12, 64 )
GUICtrlCreateLabel ( ":", 95+$Extraleft, 11, 3 )
;//////////////////////////////////////////////////////////////////// DETAILED \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\;
GUICtrlCreateGroup ( "Detailed Information", 10, 35, 250, 133+18 )
GUICtrlCreateLabel ( "Total Seconds:", 20, 55 )
GUICtrlCreateLabel ( "Total Minutes:", 20, 55+18 )
GUICtrlCreateLabel ( "Total Hours:", 20, 55+18*2 )
GUICtrlCreateLabel ( "Total Days:", 20, 55+18*3 )
GUICtrlCreateLabel ( "Total Weeks:", 20, 55+18*4 )
GUICtrlCreateLabel ( "Total Months:", 20, 55+18*5 )
GUICtrlCreateLabel ( "Total Years:", 20, 55+18*6 )
$TotalSeconds   = GUICtrlCreateLabel ( $iDateCalcseconds, 120, 55, $Length, $Height )
$TotalMinutes   = GUICtrlCreateLabel ( $iDateCalcminutes, 120, 55+18, $Length, $Height )
$TotalHours     = GUICtrlCreateLabel ( $iDateCalchours, 120, 55+18*2, $Length, $Height )
$TotalDays      = GUICtrlCreateLabel ( $iDateCalcdays, 120, 55+18*3, $Length, $Height )
$TotalWeeks     = GUICtrlCreateLabel ( $iDateCalcweeks, 120, 55+18*4, $Length, $Height )
$TotalMonths    = GUICtrlCreateLabel ( $iDateCalcmonths, 120, 55+18*5, $Length, $Height )
$TotalYears     = GUICtrlCreateLabel ( $iDateCalcyears, 120, 55+18*6, $Length, $Height )
;///////////////////////////////////////////////////////////////////// CHANGE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\;
GUICtrlSetState ( $ACopy, $GUI_FOCUS )
GUISetState ( @SW_SHOW )

While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
        Exit
    Case $ACopy
        $Pos = WinGetPos ( "Cas (L) Lizzy" )
        WinMove ( "Cas (L) Lizzy", "", $Pos[0], $Pos[1]-95 )
        $Advanced   = GUICreate ( "Advanced Copy", 275, 85, -1, $Pos[1]+165, -1, -1, $GUI )
        $Copy       = GUICtrlCreateButton ( "Copy", 10, 55, 255, 25 )
        $RSeconds   = GUICtrlCreateRadio ( "Seconds.", 10, 10 )
        $RMinutes   = GUICtrlCreateRadio ( "Minutes.", 10+70, 10 )
        $RHours     = GUICtrlCreateRadio ( "Hours.", 10+140, 10 )
        $RDays      = GUICtrlCreateRadio ( "Days.", 10+210, 10 )
        $RWeeks     = GUICtrlCreateRadio ( "Weeks.", 10, 10+20 )
        $RMonths    = GUICtrlCreateRadio ( "Months.", 10+70, 10+20 )
        $RYears     = GUICtrlCreateRadio ( "Years.", 10+140, 10+20 )
        $RTotal     = GUICtrlCreateRadio ( "Total.", 10+210, 10+20 )
        GUICtrlSetState ( $RSeconds, $GUI_CHECKED )
        GUICtrlSetState ( $Copy, $GUI_FOCUS )
        GUISetState ( @SW_SHOW )
        While 1
            Switch GUIGetMsg()
            Case $Copy
                If GUICtrlRead ( $RSeconds ) = $GUI_CHECKED Then
                    $WriteSeconds = GUICtrlRead ( $TotalSeconds )
                    ClipPut ( $WriteSeconds )
                ElseIf GUICtrlRead ( $RMinutes ) = $GUI_CHECKED Then
                    $WriteMinutes = GUICtrlRead ( $TotalMinutes )
                    ClipPut ( $WriteMinutes )
                ElseIf GUICtrlRead ( $RHours ) = $GUI_CHECKED Then
                    $WriteHours = GUICtrlRead ( $TotalHours )
                    ClipPut ( $WriteHours )
                ElseIf GUICtrlRead ( $RDays ) = $GUI_CHECKED Then
                    $WriteDays = GUICtrlRead ( $TotalDays )
                    ClipPut ( $WriteDays )
                ElseIf GUICtrlRead ( $RWeeks ) = $GUI_CHECKED Then
                    $WriteWeeks = GUICtrlRead ( $TotalWeeks )
                    ClipPut ( $WriteWeeks )
                ElseIf GUICtrlRead ( $RMonths ) = $GUI_CHECKED Then
                    $WriteMonths = GUICtrlRead ( $TotalMonths )
                    ClipPut ( $WriteMonths )
                ElseIf GUICtrlRead ( $RYears ) = $GUI_CHECKED Then
                    $WriteYears = GUICtrlRead ( $TotalYears )
                    ClipPut ( $WriteYears )
                ElseIf GUICtrlRead ( $RTotal ) = $GUI_CHECKED Then
                    MsgBox ( 0, "Error", "Still working on this" )
                EndIf
            Case $GUI_EVENT_CLOSE
                GUIDelete ( $Advanced )
                Sleep ( 300 )
                WinMove ( "Cas (L) Lizzy", "", @DesktopWidth/2-139, @DesktopHeight/2-145 )
                refresh()
                ExitLoop
            EndSwitch
        WEnd
        
    Case $Copy
        MsgBox ( 0, "lol", "lol" )
    Case $Refresh
        refresh()
    Case $Quit
        Exit
    EndSwitch
WEnd

Func ExitProg()
    Exit
EndFunc

Func refresh()
    If Not WinActive ( "Advanced Copy" ) Then
        $iDateCalcseconds    = _DateDiff ( 's',"2008/11/23 18:00:00", _NowCalc ( ) )
        $iDateCalcminutes    = _DateDiff ( 'n',"2008/11/23 18:00:00", _NowCalc ( ) )
        $iDateCalchours      = _DateDiff ( 'h',"2008/11/23 18:00:00", _NowCalc ( ) )
        $iDateCalcdays       = _DateDiff ( 'D',"2008/11/23 18:00:00", _NowCalc ( ) )
        $iDateCalcweeks      = _DateDiff ( 'w',"2008/11/23 18:00:00", _NowCalc ( ) )
        $iDateCalcmonths     = _DateDiff ( 'M',"2008/11/23 18:00:00", _NowCalc ( ) )
        $iDateCalcyears      = _DateDiff ( 'Y',"2008/11/23 18:00:00", _NowCalc ( ) )
        GUICtrlDelete ( $TotalSeconds )
        $TotalSeconds       = GUICtrlCreateLabel ( $iDateCalcseconds, 120, 55, $Length, $Height )
        GUICtrlDelete ( $TotalMinutes )
        $TotalMinutes       = GUICtrlCreateLabel ( $iDateCalcminutes, 120, 55+18, $Length, $Height )
        GUICtrlDelete ( $TotalHours )
        $TotalHours         = GUICtrlCreateLabel ( $iDateCalchours, 120, 55+18*2, $Length, $Height )
        GUICtrlDelete ( $TotalDays )
        $TotalDays          = GUICtrlCreateLabel ( $iDateCalcdays, 120, 55+18*3, $Length, $Height )
        GUICtrlDelete ( $TotalWeeks )
        $TotalWeeks         = GUICtrlCreateLabel ( $iDateCalcweeks, 120, 55+18*4, $Length, $Height )
        GUICtrlDelete ( $TotalMonths )
        $TotalMonths        = GUICtrlCreateLabel ( $iDateCalcmonths, 120, 55+18*5, $Length, $Height )
        GUICtrlDelete ( $TotalYears )
        $TotalYears         = GUICtrlCreateLabel ( $iDateCalcyears, 120, 55+18*6, $Length, $Height )
    EndIf
EndFunc

The one who makes it is my hero! ;)

.Rawox

Edited by Rawox

Share this post


Link to post
Share on other sites



Rawox,

Look at _DateDiff in the Help file and use some basic maths.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I am not really good with basic maths,, I tried this:

GUICtrlSetData ( $Second, $iDateCalc )
$iMinute = 1
$iSecond = $iDateCalc
Do
    If GUICtrlRead ( $Second ) > 60000 Then
        GUICtrlSetData ( $Minute, $iMinute )
        $iMinute += 1
        $Read = GUICtrlRead ( $Second )
        GUICtrlSetData ( $Second, $Read-60000 )
    EndIf
Until GUICtrlRead ( $Second ) < 60000

I don't know :D It does not work.

Share this post


Link to post
Share on other sites

why dont you look what Melba has already suggested?

Share this post


Link to post
Share on other sites

I've done that! But I don't get it. My english isn't really good and I am just 15 years old...

Can someone make me an example or something so I get it too?

Share this post


Link to post
Share on other sites

Rawox,

An example of _DateDiff in days for your chosen date:

#Include <Date.au3>

$sDate = "2008/11/23 18:00:00"

$Days = _DateDiff("D", $sDate, _NowCalc())

ConsoleWrite($Days & " Days" & @CRLF)

At 15 you should be able to do enough basic maths to convert time periods. If not your career as a coder will be very frustrating as almost all coding (or programming) relies on that sort of simple calulation for anything more than initial "Hello World" type scripts.

Give it a go yourself and come back if you have problems - and I do NOT mean in 5 minutes! ;-)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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