PDA

View Full Version : DT_DateToSec



Michael Clease
19-04-2009, 00:08
I was looking at DT_DateToSec and was wondering where it does its calculation from is it 01-01-1970 or 01-01-1900 or ??

ErosOlmi
19-04-2009, 00:30
As far as I know it starts from date "01-01-0000" so from the first day of the first month of year zero.
Roberto will be more precise.

Number of seconds of the very first day:

uses "Console", "dt"
printl DT_DateToSec("01-01-0000")
waitkey

peralta_mike
22-04-2011, 21:21
Subj: DT_DateToSec and DT_SecTo_Date Only Seem To Work for > 4 A.D. or so.

If you try the following tb script the functions
DT_DateToSec and DT_SecTo_Date
only seem to work for > 4 A.D. or so.


'=====================================================
uses "console","dt"

console_write "01-01-1970 -> " & dt_datetosec("01-01-1970") & $CRLF
console_write "01-01-0004 -> " & dt_datetosec("01-01-0004") & $CRLF
console_write "01-01-0001 -> " & dt_datetosec("01-01-0001") & $CRLF
console_write "01-01-0000 -> " & dt_datetosec("01-01-0000") & $CRLF
console_write "63000000000 secs -> " & dt_sectodate(63000000000) & $CRLF
console_write "10000000000 secs -> " & dt_sectodate(10000000000) & $CRLF
console_write "1000000000 secs -> " & dt_sectodate(1000000000) & $CRLF
console_write "100000000 secs -> " & dt_sectodate(100000000) & $CRLF
console_write "10000000 secs -> " & dt_sectodate(10000000) & $CRLF
console_write "1000000 secs -> " & dt_sectodate(1000000) & $CRLF
console_write "100000 secs -> " & dt_sectodate(100000) & $CRLF
console_write "10000 secs -> " & dt_sectodate(10000) & $CRLF
console_write "1000 secs -> " & dt_sectodate(1000) & $CRLF
console_write "100 secs -> " & dt_sectodate(100) & $CRLF
console_write "10 secs -> " & dt_sectodate(10) & $CRLF
console_write "1 secs -> " & dt_sectodate(1) & $CRLF
console_write "0 secs -> " & dt_sectodate(0) & $CRLF
console_waitkey
'===================================================

peralta_mike
23-04-2011, 14:52
Can this be fixed?
Also how can I confirm that the datetosec and sectodate formulas are working correctly for dates after Jan 1, 1970 ?

peralta_mike
26-04-2011, 16:06
Any info on this? :confused:

ErosOlmi
26-04-2011, 17:33
I will check this night when back home

Simone
26-04-2011, 18:07
Hi all,

I know why the function "DateToSec" doesn't work, for now the first date that work is 01-01-0002

I talk about this problem with Eros.

Ciao,
Simone

zak
26-04-2011, 18:56
there is a book of Peter Duffett-Smith : Practical Astronomy With Your Calculator
(http://books.google.co.uk/books?id=DwJfCtzaVvYC&dq=practical+astronomy+with+your+calculator&printsec=frontcover&source=bn&hl=en&ei=QSSMTJ6XH8qNjAeo2KyMBg&sa=X&oi=book_result&ct=result&resnum=4&ved=0CCMQ6AEwAw#v=onepage&q&f=false)
describe how to find the number of days lapsed from year January 1, 4713 BC Greenwich noon http://en.wikipedia.org/wiki/Julian_day to any day of choice. so the julian day begins at 12 noon. if i am not wrong we can convert it to seconds by *24*60*60. the algorithm described in page 7 . may be this info can be used somehow. attached page 7 from google books i salvages from temporary internet files cache, i hope it is not harming the book copyright, if so Eros can delete it. i have tried the algorithm in the book to see the days between 1902,1,17 and 2011,4,26, it turns that it is 39911 days and using the DT_DateToSec it return 39911.
i think the zero year in astronomy is like 1900, 1800, etc
this site also calculate julian days
http://aa.usno.navy.mil/data/docs/JulianDate.php
http://www.hermetic.ch/cal_stud/jdn.htm


Uses "Console", "dt"
Dim dt,dt2,difdt As Extended
dt = DT_DateToSec("01-17-1902")
dt2 = DT_DateToSec("04-26-2011")
difdt=(((dt2-dt)/60)/60)/24 'number of days between ...
PrintL difdt
Dim days, daysTo, dif As Extended
days = julian(1902,1,17)
days = days - 0.5
daysTo = julian(2011,4,26)
daysTo = daysTo - 0.5
dif = daysTo - days
PrintL dif
WaitKey
'===========================================
Function julian(y As Extended,m As Extended,d As Extended)
Dim y1,m1,d1,B,C,DD,A,JD As Extended
If m=1 Or m=2 Then
y1=y-1:m1=m+12
Else
y1=y:m1=m
End If
If y>=1582 Then
A=Int(y1/100)
B=2-A+Int(A/4)
Else
B=0
End If
If y1<0 Then
C=Int(365.25*y1)-0.75
Else
C=Int(365.25*y1)
End If
DD=Int(30.6001*(m1+1))
JD=B+C+DD+d+1720994.5
Function = JD
End Function

ErosOlmi
26-04-2011, 22:18
Ok, I think I've got something working hopefully.

Please get attached thinBasic Date module and manually copy into thinBasic library directory in this way: unzip "thinBasic_DT.DLL" into \thinBasic\Lib\ directory replacing your current file.

I've made some tests but not all the tests I would have liked. Tomorrow, with the help of Simone, I will perform more tests and if needed I will amend again Date module. For your info, I work together with Simone in an Italian company.

The following code seems working as expected. If you have some tests resulting in wrong output, just post your code and I will have a look tomorrow.


Uses "Console"
Uses "DT"

DT_SetDateSeparator("/")

Dim lCounter As Long
Dim nDates As Long = 12
Dim sDates(nDates) As String

sDates( 1) = DT_GetDate
sdates( 2) = "01-01-1970"
sdates( 3) = "01-17-1902"
sDates( 4) = "02-29-0004"
sDates( 5) = "01-01-0003"
sDates( 6) = "12-31-0002"
sDates( 7) = "01-01-0001"
sDates( 8) = "12-31-0000"
sDates( 9) = "12-30-0000"
sDates(10) = "01-02-0000"
sDates(11) = "01-01-0000"
sDates(12) = "00-00-0000"

For lCounter = 1 To nDates
If Len(sDates(lCounter)) = 0 Then Iterate For
PrintL "DateToSec: " & sDates(lCounter) & " -> " & RSet$(DT_DateToSec(sDates(lCounter)), 12) & " " & _
"SecToDate: " & DT_SecToDate(DT_DateToSec(sDates(lCounter)))
Next

PrintL "---Press any key to continue---"
WaitKey


Output of the above program:


DateToSec: 04/26/2011 -> 63471081600 SecToDate: 04/26/2011
DateToSec: 01-01-1970 -> 62167305600 SecToDate: 01/01/1970
DateToSec: 01-17-1902 -> 60022771200 SecToDate: 01/17/1902
DateToSec: 02-29-0004 -> 131414400 SecToDate: 02/29/0004
DateToSec: 01-01-0003 -> 94780800 SecToDate: 01/01/0003
DateToSec: 12-31-0002 -> 94694400 SecToDate: 12/31/0002
DateToSec: 01-01-0001 -> 31708800 SecToDate: 01/01/0001
DateToSec: 12-31-0000 -> 31622400 SecToDate: 12/31/0000
DateToSec: 12-30-0000 -> 31536000 SecToDate: 12/30/0000
DateToSec: 01-02-0000 -> 172800 SecToDate: 01/02/0000
DateToSec: 01-01-0000 -> 86400 SecToDate: 01/01/0000
DateToSec: 00-00-0000 -> 0 SecToDate: 00/00/0000
---Press any key to continue---

peralta_mike
27-04-2011, 16:34
My tests so far show good results.
Later, I will compare more recent dates against my Perl and C library results.

Thanks.

btw
There are only 4 digits in the year.
What about when we hit the year 10000?
The dreaded Y10K problem.
lol, hehehe just kidding. ;)
We won't have to worry about that for a while.


' --- trydt.bas April 27, 2011 ---
uses "console","dt"
console_write "01-01-1970 -> " & dt_datetosec("01-01-1970") & $CRLF
console_write "01-01-0004 -> " & dt_datetosec("01-01-0004") & $CRLF
console_write "01-01-0003 -> " & dt_datetosec("01-01-0003") & $CRLF
console_write "01-01-0002 -> " & dt_datetosec("01-01-0002") & $CRLF
console_write "01-01-0001 -> " & dt_datetosec("01-01-0001") & $CRLF
console_write "01-01-0000 -> " & dt_datetosec("01-01-0000") & $CRLF
console_write "63000000000 secs -> " & dt_sectodate(63000000000) & $CRLF
console_write "10000000000 secs -> " & dt_sectodate(10000000000) & $CRLF
console_write "1000000000 secs -> " & dt_sectodate(1000000000) & $CRLF
console_write "100000000 secs -> " & dt_sectodate(100000000) & $CRLF
console_write "10000000 secs -> " & dt_sectodate(10000000) & $CRLF
console_write "1000000 secs -> " & dt_sectodate(1000000) & $CRLF
console_write "100000 secs -> " & dt_sectodate(100000) & $CRLF
console_write "10000 secs -> " & dt_sectodate(10000) & $CRLF
console_write "1000 secs -> " & dt_sectodate(1000) & $CRLF
console_write "100 secs -> " & dt_sectodate(100) & $CRLF
console_write "10 secs -> " & dt_sectodate(10) & $CRLF
console_write "1 secs -> " & dt_sectodate(1) & $CRLF
console_write "0 secs -> " & dt_sectodate(0) & $CRLF
console_waitkey