Results 1 to 10 of 10

Thread: DT_DateToSec

  1. #1
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    DT_DateToSec

    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 ??

    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: DT_DateToSec

    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
    
    Last edited by ErosOlmi; 23-04-2011 at 19:19.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    Member
    Join Date
    Jul 2010
    Location
    Phoenix, Arizona, usa
    Age
    74
    Posts
    54
    Rep Power
    19

    Unhappy DT_DateToSec and DT_SecTo_Date Only Seem To Work for > 4 A.D. or so

    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
    '===================================================
    
    Last edited by ErosOlmi; 26-04-2011 at 20:39.

  4. #4
    Member
    Join Date
    Jul 2010
    Location
    Phoenix, Arizona, usa
    Age
    74
    Posts
    54
    Rep Power
    19

    Question Can we fIx this bug?

    Can this be fixed?
    Also how can I confirm that the datetosec and sectodate formulas are working correctly for dates after Jan 1, 1970 ?

  5. #5
    Member
    Join Date
    Jul 2010
    Location
    Phoenix, Arizona, usa
    Age
    74
    Posts
    54
    Rep Power
    19

    Where can I get info on the DT_DateToSec & DT_SecToDate formulas

    Any info on this?

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    I will check this night when back home
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7
    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
    LapTop Pc: 2GHz Intel Core 2 Duo T7200 • 2GB 533MHz DDR2 RAM • 160GB hard disk • 512MB ATi Mobility Radeon X1600 graphics • Win Vista SP1<br />Desktop Pc: 1.6GHz Intel Core 2&nbsp; • 2GB DDR2 RAM •&nbsp; 1024MB Nvidia GeForce 8800 GT • WinXp&nbsp; SP3

  8. #8
    there is a book of Peter Duffett-Smith : Practical Astronomy With Your Calculator

    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
    
    Attached Files Attached Files

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    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---
    
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  10. #10
    Member
    Join Date
    Jul 2010
    Location
    Phoenix, Arizona, usa
    Age
    74
    Posts
    54
    Rep Power
    19

    Works Great. Thanks Eros.

    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

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •