|
Post by votan on Sept 16, 2008 1:27:20 GMT -5
How can I get the hours and minutes passed since jan. 1st 1901 both as a seperate value?
|
|
|
Post by mackrackit on Sept 16, 2008 1:54:11 GMT -5
I do not know how to get the time from 1901, but if you can do that this might help
Tvar$ = time$() print Tvar$ print "Hour ";mid$(Tvar$,1,2) print "Minute ";mid$(Tvar$,4,2) print "Second ";mid$(Tvar$,7,2)
|
|
|
Post by votan on Sept 16, 2008 2:32:32 GMT -5
;D... just discovered a "user-friendly bug" in the time$ command.... using time$("seconds") actually does show seconds passed since 1.1.1901 instead of seconds passed since midnight of the current day (like stated in the building blocks). Anyway, please do not exterminate this bug, as it is much better this way (and maybe even was intended this way!?)! Cause now I can do all sorts of time calculations the easy way!! btw.... same applies to miliseconds.... seconds = time$("seconds") minutes = int(seconds / 60) hours = int(minutes / 60) days = int(hours / 24) date = date$("days")
print "seconds since jan. 01 1901 : ";seconds print "minutes since jan. 01 1901 : ";minutes print "hours since jan. 01 1901 : ";hours print "days since jan. 01 1901 (calculated) : ";days print "days since jan. 01 1901 (system): ";date And if you still need to know the passed seconds since midnight, it is not hard to do either....
|
|
|
Post by Janet on Sept 16, 2008 7:27:59 GMT -5
Having milliseconds count from 1901 certainly prevents the problem of counting a time period that extends from pre-midnight to post-midnight. I could see an advantage to this as well, so long as it's been verified by Carl and correctly documented.
|
|
|
Post by kokenge on Sept 26, 2008 5:28:47 GMT -5
As an alternative you might consider using SQLite to do your date calculations. It has a lot of date functions, and IMO it's a lot easier to use with a lot more power and functions. www.sqlite.org/lang_datefunc.htmlFor example I have a calendar routine and need to know what week day the month starts, and how many days are in the month. No real SQLite database is needed. I simply open a DB that only exist in "memory" and supply the month and year I want. However if you already have a SQLite DB that your program has open, you can use it. [getMonthInfo] ' ---------------------------------------- ' day of week when month begins. ' days in a month ' supply yr = year , mm = month ' ---------------------------------------- dayOne$ = str$(yr) ; "-" ; right$("0";str$(mm),2) ; "-01" sqliteconnect #mem, ":memory:" sql$ = "SELECT strftime ( '%w','";dayOne$;"') as dow, date('";dayOne$;"','start of month','+1 month','-1 day') as emo" #mem execute(sql$) result$ = #mem nextrow$(" |") dow = val(word$(result$,1,"|")) ' Day of Week month begins eom$ = trim$(word$(result$,2,"|")) ' End of month mmDays = val(word$(eom$,3,"-")) ' Days in Month
RETURN
HTH..
|
|
|
Post by kokenge on Sept 26, 2008 6:22:56 GMT -5
I may toss another example in. Usually there is no need to compute the time outside the SQL. It can be computed in the fly in the query itself.
Here is an example where I have assets scheduled in the table "schTime". It has the assetNum and the schBeg (begin) and schEnd (end) times that are scheduled. Assets can be anything like a conference room, machine or whatever. If someone needs a asset for a particular amount of time (minSlots), it finds elapse time gaps between schedules and shows them all the available times slots that meet that requirement.
SELECT s.schNum,s.assetNum,s.schEnd as preEnd,s1.schBeg as nxtBeg, ((strftime('%s',s1.schBeg) - strftime('%s',s.schEnd)) / 60) as laps, (strftime('%w',s.schEnd)) as dowBeg FROM schTime as s JOIN schTime as s1 ON s1.assetNum = s.assetNum AND s1.schBeg > s.schEnd AND ((strftime('%s',s1.schBeg) - strftime('%s',s.schEnd)) / 60) >= ";minSlots;" AND s1.schBeg = (SELECT min(s2.SchBeg) FROM schTime as s2 WHERE s2.assetNum = s.assetNum AND s2.schBeg > s.schEnd) WHERE s.assetNum = ";assetNum;" AND s.schBeg >= ";begSlotDate$;" LIMIT ";numSlots
Too much fun...
|
|