View previous topic :: View next topic |
Author |
Message |
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Fri Jun 28, 2002 8:36 pm Post subject: Find Elapsed Time (hr/min/sec)... |
|
|
Here's a simple routine to demonstrate finding
hours/minutes/seconds elapsed between a start
and an end time.
As near as I can tell, you must retrieve start/end
time floats when they happen. Although you can
retrieve a @datetime() float for any date, I haven't
found a way to retrieve a float using an arbitrary
time (such as 12:15 pm).
I left the math functions separate for clarity.
__________________________________________________________________________________________________________________________
Code: |
OPTION SCALE, 96
OPTION DECIMALSEP, "."
TITLE By Mac
DIALOG CREATE,"Find Elapsed Time",-1,0,180,130,SMALLCAPS
DIALOG ADD,BUTTON,Start,5,5,50,20
DIALOG ADD,BUTTON,Stop,5,60,50,20
DIALOG ADD,Text,T1,30,5,170,80,""
DIALOG ADD,STATUS,Stat
DIALOG SHOW
:StopBUTTON
:EVLOOP
DIALOG SET, Stat, "Ready..."
WAIT EVENT
goto @event()
:StartBUTTON
DIALOG CLEAR, T1
rem -- The start time float MUST be retrieved at actual start time --
%%start = @format(@datetime(), 6.8)
rem -- Let some time pass --
REPEAT
DIALOG SET, Stat, @datetime()
UNTIL @event()
rem -- The end time float MUST be retrieved at actual end time --
%%end = @format(@datetime(), 6.8)
rem -- Get difference between start/end times --
%%answer = @format(@fsub(%%end, %%start), 6.9)
rem -- Convert to hours|minutes|seconds --
%%answer = @datetime(hh|nn|ss,%%answer)
rem -- Parse into vars --
PARSE "%%hrs;%%mins;%%secs", %%answer
DIALOG SET, T1, "Started = "%%start@cr()" Ended = "%%end@cr()@cr()%%hrs hours@cr()%%mins minutes@cr()%%secs seconds
goto EVLOOP
:CLOSE
EXIT
|
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
LOBO Valued Contributor
Joined: 14 Mar 2002 Posts: 241 Location: Wilmington, Delaware, USA
|
Posted: Wed Sep 11, 2002 2:41 pm Post subject: |
|
|
Is there a way without physically changing the clock and calendar to get the float for a specific date and time? Example is say I want to hard code a set date and time (5/1/2000 10:00am) then run a variation of Mac's elasped time code.
Regards,
Mark |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Wed Sep 11, 2002 2:57 pm Post subject: |
|
|
Here's how to get the float for a date only, if that helps any
(ya may have to use something besides "/", depending
on what your system uses as a date separator):
Code: |
%d = @datetime(, 05/01/2000)
INFO test %d
|
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
LOBO Valued Contributor
Joined: 14 Mar 2002 Posts: 241 Location: Wilmington, Delaware, USA
|
Posted: Wed Sep 11, 2002 3:31 pm Post subject: |
|
|
Thanks Mac,
I had figured out the date portion, but I was looking for the time float and wasn't sure if the date would need to be included or not. I'll keep playing and checking to find out how to find the time float. If anybody figures out how to get the time float it would be greatly appreciated if it would be posted. |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Wed Sep 11, 2002 3:33 pm Post subject: |
|
|
Well, here's an idea...
Apparently, numbers to the left of the decimal represent
the date, and those to the right represent the time.
So... if ya check the floating point at 10:00 AM, you can add
the decimal part to the date retrieved by the previous
example: %d = @datetime(, 05/01/2000)
Or ya could get the decimal equivalent for a minute
(or whatever) and do some math...
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
Posted: Wed Sep 11, 2002 5:55 pm Post subject: |
|
|
Please note that code this won't work on all Windows versions, depending on regional settings:
%d = @datetime(, 05/01/2000)
For example on my system I would have to use the following to prevent an error 13 occuring:
%d = @datetime(, 01-05-2000) |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Wed Sep 11, 2002 6:06 pm Post subject: |
|
|
I mentioned that where I first posted the function Tommy.
Here's the info I've figured out from a @datetime() float:
The DATE is to left of the decimal.
The TIME is to the right of the decimal.
1 whole number = 24 hours = 1440 minutes = 86400 seconds
1 hour = .041666668
1 minute = .00069444447
1 second = .0000115740745
I also posted this in the knowledge base.
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
Posted: Wed Sep 11, 2002 6:54 pm Post subject: |
|
|
Thanks Mac. |
|
Back to top |
|
|
LOBO Valued Contributor
Joined: 14 Mar 2002 Posts: 241 Location: Wilmington, Delaware, USA
|
Posted: Thu Sep 12, 2002 12:22 am Post subject: |
|
|
Thanks Mac Very much appreciated |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Thu Sep 12, 2002 12:28 am Post subject: |
|
|
Glad to help out guys.
Just a thought: When checking floats for a time in the future,
I'd use @greater() rather than @equal() to test values (in
case VDS misses the exact value by a fraction).
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
Que Valued Newbie
Joined: 25 Aug 2001 Posts: 38 Location: Newaygo, MICH
|
Posted: Mon Sep 23, 2002 3:27 pm Post subject: |
|
|
Good stuff guys... I had a need to calculate week ending, which, thanks to Mac pointing out that 1 = 1 day, I was able to do. While I was at it, I went ahead and did a few extra calcs. The script was kind of for my reference, so it also includes outcome for all @datetime parameters on the first info box... Calcs include:
Date for End of Previous Week (based on Sunday being end of week)
Days and Date for End of Current Week
Date for End of Next Week
Days and Date for End of Current Month
Days and Date for End of Current Year
Days and Date for Christmas
Please note: I have never claimed to be a creator of Clean Code Hey! It works ok...
Code: |
%d = @datetime(d)
%%dd = @datetime(dd)
%%ddd = @datetime(ddd)
%%dddd = @datetime(dddd)
%%ddddd = @datetime(ddddd)
%%dddddd = @datetime(dddddd)
%m = @datetime(m)
%%mm = @datetime(mm)
%%mmm = @datetime(mmm)
%%mmmm = @datetime(mmmm)
%%yy = @datetime(yy)
%%yyyy = @datetime(yyyy)
info "When Using the @datetime() function:"@cr()d = %d@cr()dd = %%dd @cr()ddd = %%ddd @cr()dddd = %%dddd @cr()ddddd = %%ddddd @cr()dddddd = %%dddddd @cr()m = %m @cr()mm = %%mm @cr()mmm = %%mmm @cr()mmmm = %%mmmm @cr()yy = %%yy @cr()yyyy = %%yyyy @cr()
:End of week
%%days = -1
repeat
%%days = @succ(%%days)
%%day = @datetime(ddd,@fadd(@datetime(),%%days))
until @equal(%%day,Sun)
%%Prevweekending = @datetime(ddddd,@fsub(@fadd(@datetime(),%%days),7))
%%nextweekending = @datetime(ddddd,@fadd(@fadd(@datetime(),%%days),7))
info Previous Week Ending = %%prevweekending@cr()%%days days til the end of the week = @datetime(ddddd,@fadd(@datetime(),%%days))@cr()Next Week Ending = %%nextweekending
:End of Month
%%days = -1
repeat
%%days = @succ(%%days)
%%month = @datetime(m,@fadd(@datetime(),%%days))
until @greater(%%month,%m)
%%days = @pred(%%days)
info %%days days til the end of the month = @datetime(ddddd,@fadd(@datetime(),%%days))
:End of year
%%days = -1
repeat
%%days = @succ(%%days)
%%year = @datetime(yyyy,@fadd(@datetime(),%%days))
until @greater(%%year,%%yyyy)
%%days = @pred(%%days)
info %%days days til the end of the year = @datetime(ddddd,@fadd(@datetime(),%%days))
:christmas
%%days = -1
repeat
%%days = @succ(%%days)
%%xmo = @datetime(m,@fadd(@datetime(),%%days))
%%xda = @datetime(d,@fadd(@datetime(),%%days))
until @both(@equal(%%xmo,12),@equal(%%xda,25))
info %%days days til Christmas = @datetime(ddddd,@fadd(@datetime(),%%days))
|
_________________ Que |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|