# Re: Help

Moderator

This code is untested! You'll have to test it yourself. Please report bugs.

Regards,
Michael

CONST monthsinyear = 12
CONST hoursinday = 24
CONST minsinhour = 60
CONST secsinmin = 60
CONST secsinhour = secsinmin * mininhour
CONST secsinday = secsinhour * hoursinday
CONST daysinnonleap = 365

'get boot date/time

'try to make sure DATE\$ doesn't change before we can get TIME\$
DO
ndate\$ = DATE\$
ntime\$ = TIME\$
LOOP WHILE TIMER < 2

'from here up: public domain

nowmonth = VAL(LEFT\$(ndate\$, 2)) 'the month isolated from DATE\$
nowday = VAL(MID\$(ndate\$, 4, 2)) 'the day isolated from DATE\$
nowyear = VAL(RIGHT\$(ndate\$, 4)) 'the year isolated from DATE\$
nowhour = VAL(LEFT\$(ntime\$, 2)) 'the hour isolated from TIME\$
nowminute = VAL(MID\$(ntime\$, 4, 2)) 'the minute isolated from TIME\$
nowsecond = VAL(RIGHT\$(ntime\$, 2)) 'the second isolated from TIME\$

'from here on: public domain
'untested!

DIM elaps AS DOUBLE, l AS LONG, i AS INTEGER

elaps = 0

FOR l = bootyear + 1 TO nowyear - 1
elaps = elaps + secsinyear(l)
NEXT

FOR i = bootmonth + 1 TO monthsinyear
elaps = elaps + secsinmonth(i, bootyear)
NEXT
FOR i = 1 TO nowmmonth - 1
elaps = elaps + secsinmonth(i, nowyear)
NEXT

elaps = elaps + (daysinmonth(bootmonth, bootyear) - bootday) * secsinday
elaps = elaps + (nowday - 1) * secsinday

elaps = elaps + (hoursinday - 1 - boothour) * secsinhour
elaps = elaps + nowhour * secsinhour

elaps = elaps + (minsinhour - 1 - bootminute) * secsinmin
elaps = elaps + nowminute * secsinmin

elaps = elaps + secsinmin - bootsecond
elaps = elaps + nowsecond

FUNCTION secsinyear& (year AS LONG)
secsinyear = secsinday * (daysinnonleap - isleap(year))
END FUNCTION

FUNCTION daysinmonth% (month AS INTEGER, year AS LONG)
SELECT CASE month
CASE 2: daysinmonth = 29 - isleap(year)
CASE 4, 6, 9, 11: daysinmonth = 30
CASE ELSE: daysinmonth = 31
END SELECT
END FUNCTION

FUNCTION secsinmonth& (month AS INTEGER, year AS LONG)
secsinmonth = secsinday * daysinmonth(month, year)
END FUNCTION

FUNCTION isleap& (year AS LONG)
isleap = (year MOD 4 = 0 AND year MOD 100 <> 0) OR year MOD 400 = 0
END FUNCTION

P.S. The number one and the letter el are almost visually indistinguishable when I view this post. When you copy/paste the code to notepad or QB64, you will be able to distinguish them.

 This message has been edited by MCalkins on Mar 21, 2012 1:21 AMThis message has been edited by MCalkins on Mar 21, 2012 1:20 AM

Posted on Mar 21, 2012, 1:17 AM

Respond to this message