time between date and times
BlitzMax Forums/BlitzMax Beginners Area/time between date and times
| ||
I have done a bit of searching but not found anything that got me closer, so I figured you guys might know of some clever code :) I need a function which will allow me to input two dates and times, eg. 13 sep 2008 11:32:04 15 sep 2008 17:12:52 and then have the function return to me how much time is left. The time it returns can be millisecs if that is easier. I will continue to tinker with it, but if any of you knows how to do this already, I would appreciate a helping hand. |
| ||
There's something in the code archives that does this for the dates at least. Search for 'julian', I think. IIRC, It's Blitzbasic code but it won't be much of an ordeal to convert it to run in Max, if it needs converting at all. Its just maths stuff. [edit] http://www.blitzbasic.com/codearcs/codearcs.php?code=451 That'll *almost* work in Blitzmax right off the bat. You'll need to fix up the array declaration though, as they're defined as Global Month:string[12] in Blitzmax. Also bear in mind that this creates an array with 12 elements numbered 0 to 11, so you'll need to change the second line containing the array contents, too, since they start at 1 and count up to 12. Just change it to go from 0 to 11, or add define the array with 13 elements instead of 12. Either, or. [edit again] 'Credit to Imphenzia for original code Global Months:String[12] Months(0)="JAN";Months(1)="FEB";Months(2)="MAR";Months(3)="APR";Months(4)="MAY";Months(5)="JUN"; Months(6)="JUL"; Months(7)="AUG"; Months(8)="SEP"; Months(9)="OCT"; Months(10)="NOV"; Months(11)="DEC" Print "Days between today and 25 Dec 2008: " + (JulianDays("25 DEC 2008") - JulianDays(CurrentDate())) Function FindMonth(fm$) For i=0 To 11 If Upper(fm$)=months$(i) Then Return i Next End Function Function JulianDays(txt$) d=Int(Left(txt$,2)) m=Int(FindMonth(Mid(txt$,4,3))) y=Int(Right(txt$,4)) jd=( 1461 * ( y + 4800 + ( m - 14 ) / 12 ) ) / 4 + ( 367 * ( m - 2 - 12 * ( ( m - 14 ) / 12 ) ) ) / 12 - ( 3 * ( ( y + 4900 + ( m - 14 ) / 12 ) / 100 ) ) / 4 + d - 32075 Return jd End Function |
| ||
There is although Brucey's timedate module. Perhaps it's overkill, but you can find it here: http://brucey.net/programming/blitz/#bahdatetime |
| ||
try this http://www.blitzbasic.com/codearcs/codearcs.php?code=1726 in code archives |
| ||
Not sure I need a complete module, but the above postings is getting me in the right direction. Thanks. I will glance the module over just in case though :) |