BBS: Inland Empire Archive Date: 07-19-92 (19:49) Number: 31 From: JEAN CREPEAU Refer#: NONE To: STEVE MATHIESON Recvd: NO Subj: Unix Style Timestamps??? Conf: (2) Quik_Bas
In a message to ALL, STEVE MATHIESON wrote: SM=> Howdy All! SM=> Can anyone explain to me how to deal with Unix style timestamps? I'm writting a program and one of the files it reads contains such a field, and for the life of me, I can't figure out how to make it into something more readable. It's basically a large number that represents the number of seconds since January 1 1970, and it _should_ be possible to get the date and time out of this number. But I don't know how... Can anyone help? deflng a-z function getcode (yy,mm,dd,h,m,s) getcode=(getct(yy,mm,dd)-getct(1970,1,1))*86400+s+60*m+3600*h end function function getct (y,m,d) z=y+(m < 3) x=z*365+z\4-z\100+z\400+d select case m case 1:x=x+365 case 2:x=x+396 case 3:x=x+59 case 4:x=x+90 case 5:x=x+120 case 6:x=x+151 case 7:x=x+181 case 8:x=x+212 case 9:x=x+243 case 10:x=x+273 case 11:x=x+304 case 12:x=x+334 end select getct=x end function sub getdatetime (code,yy,mm,dd,h,m,s) cd=int(code/86400):ct=code-cd*86400 yy=1970:mm=1:dd=cd:cd=cd+getct(1970,1,1) do q=cd-getct(yy,mm,dd) dd=dd+q select case mm case 1,3,5,7,8,10,12:nd=31 case 2:nd=28-((yy\4)*4=yy)+((yy\100)*100=yy)-((yy\400)*400=yy) case else:nd=30 end select nm=int((dd-1)/nd):dd=dd-nm*nd:mm=mm+nm ny=int((mm-1)/12):mm=mm-ny*12:yy=yy+ny if ny=0 and nm=0 and q=0 then exit do loop end sub To convert a Unix Stamp (Code) to YY-MM-DD, HH:MM:SS: GetDateTime Code,YY,MM,DD,H,M,S To convert time/date to a Unix Stamp Code=GetCode(YY,MM,DD,H,M,S) The other function is used to compute date codes (number of days since 00- 00-0000). You can use it to compute the number of days between to dates or to get the day of the week DayOfWeek=GetCT(YY,MM,DD) mod 7 Select case DayOfWeek case 0:print "Saturday" case 1:print "Sunday" case 2:print "Monday" case 3:print "Tuesday" case 4:print "Wednesday" case 5:print "Thursday" case 6:print "Friday" end select Jean --- * Origin: INTERACESS Montreal (QC) Canada (514) 528-1415 (1:167/280)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET