Page 1 of 1

Epoch January 1, 2000

Posted: Mon Mar 18, 2013 7:21 pm
by SFSxOI
Does anyone know if the Epoch date/time of 01/01/1970 0:00:00 can be changed in some way for use with the Date() function?

The help for Date() has this example:
Date(1999, 12, 31, 23, 59, 59) ; will print '946684799' (number of seconds between 01/01/1970 0:00:00 and 12/31/1999 23:59:59)
I need the number of seconds since midnight (UTC), January 1, 2000 (modulo 2^32) to whatever the current date is (or may be), just the number of seconds will do.

The example in the help file is perfect as its short and to the point but unfortunately the restricted nature of Date() by using the Unix Epoch makes the use of a short to the point help Date() type of thing not suitable in this case. So, can the Date() function Epoch date/time be set to something else some way?

Edit: Never mind, I decided to go another route and use the number of days since the 2000 Epoch (which is the number of Julian days since the 2000 Epoch) converted to seconds, then added to UTC hours & minutes converted to seconds then added to the current number of present day seconds less than a minute based upon a call to the GetSystemTime() API. Then I have an IEEE\IANA\IETF compliant timestamp to use for generating Type 1 & 2 DHCPIPv6 DUID's

Re: Epoch January 1, 2000

Posted: Tue Mar 19, 2013 1:45 am
by glomph
Hi,
try it with julian day calculating:

Code: Select all

;===========================
; Difference off Dates in seconds
; Source of knowledge :
; Jean Meeus "Astronomical Algorithms", german version
; Wikipedia has more information about "Julian Day".
; done by glomph 19.3.2013
; free code
; pb 5.11 beta 3
;===========================
EnableExplicit
Global jul_start.d ; 1. date
Global jul_2.d  ; 2. date
Global sek_diff.d ; difference

Declare.d julianday(day,month,year,hour,minute,second)

Procedure.d julianday(day,month,year,hour,minute,second) 
  
  Protected a.d, b.d, taf.d, mo.d, jar.d,time.d, jul_tag.d
  
  taf = day
  mo  = month
  jar = year
  
  If mo < 3
    mo  = mo + 12
    jar = jar - 1
  EndIf
  a = 0
  b = 0
  
  If jar < 0 ;year B.C. If  historical, in astronomical counting jar+1 schould be skipt
    jar + 1
  EndIf
  
  If jar + mo / 100 + taf / 10000 >= 1582.1015
    a = IntQ(jar / 100)
    b = 2 - a + IntQ(a / 4)
  EndIf
  
  time= hour / 24 + minute / 1440 + second /86400 ;convert time 0-24 in range  0.00-1.00  
  
  jul_tag = IntQ(365.25 * (jar+ 4716 )) + IntQ(30.6001 * (mo + 1 )) + b -1524.5 + taf + time
  ProcedureReturn jul_tag
  
EndProcedure

jul_start=julianday(1,1,2000,0,0,0)
Debug "Julian day 01.01.2000, 0h, 0m 0 s: "+jul_start

jul_2=julianday(2,1,2000,0,1,0)
Debug "Julian day 02.01.2000, 0h, 1m 0 s: "+jul_2

sek_diff=Round( ( jul_2 - jul_start ) * 86400, #PB_Round_Nearest)
Debug "Difference in seconds: " + sek_diff
regards
glomph

www.astroprozessor.eu

Re: Epoch January 1, 2000

Posted: Tue Mar 19, 2013 11:25 am
by SFSxOI
glomph;

Thanks for your reply.

I ended up using another method for calculating the number of (Julian) days between two dates - to meet my needs plus I can get it certified for use.

Even if the Epoch date for the PureBasic Date() function could be changed in some way for the Epoch date/time I can't get the PureBasic Date() function certified for use because it would be a modification of the intended function because such capability is not outlined in the documentation for PureBasic and does not exist evidently. If the Date() function were to natively support a change in the Epoch date/time as part of its intended function and the help said that then I could get it certified for use and could have used the simple help example which would have greatly cut down on the amount of code, but it doesn't so can't use it.