Announcement

Collapse
No announcement yet.

DateAdd Function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • DateAdd Function

    Hi all,

    Stump'd as usual...

    Here's my problem:

    Code:
    In VB - The DateAdd Function makes it easy!
    
    dwAddDate = 1044890128
    dwBiasTimeSecs = 32400
    strStartDate$ = "1/1/1970"
    
    DateOfEvent$ = DateAdd("s", CLng(dwAddDate) - dwBiasTimeSecs, strStartDate$)

    DateOfEvent$ results will equal: "2/10/2003 6:15:28 AM"

    How do I do the equivalent in PowerBasic?


    Regards
    Mike


    mwm

  • #2
    see http://www.powerbasic.com/support/pb...ad.php?t=23736

    ------------------

    Comment


    • #3
      Peter,

      Too many problems with the source code! (at least with PB7)
      GPF's all over the place!

      Regards
      Mike
      mwm

      Comment


      • #4
        I think everything you need is here. Shout if not.

        Code:
        '%DateOffset = 584388                ' Subtraction of this value to the date
                                             ' numbers will render returns the same
                                             ' values as Windows' FileTime date number
                                             ' NOTE: Sunday = ((Days MOD 7) = 1)
                                             ' NOTE: Dates before 1601-01-01 are invalid
                                             '       for Windows
        '%DateOffset = 685195                ' Jan. 1, 1877 was a Monday and Subtraction
                                             ' of this number will render the return in
                                             ' WORD format. Last Date would be 2056-12-31
        %DateOffset = 0                      '
        
        FUNCTION fLeapYear ALIAS "fLeapYear" (BYVAL Year AS LONG) EXPORT AS LONG
        
          IF ( ( Year MOD   4 ) = 0 ) AND _
             ( ( Year MOD 100 ) > 0 )  OR _
             ( ( Year MOD 400 ) = 0 ) THEN FUNCTION = 1
        
        END FUNCTION
        '
        '
        '
        FUNCTION fJulianDay ALIAS "fJulianDay" (BYVAL Year  AS LONG, _
                                                BYVAL Month AS LONG, _
                                                BYVAL Day   AS LONG  ) EXPORT AS LONG
        
          Day = Day + VAL(READ$(Month))
          IF Month > 2 THEN
            Day = Day + fLeapYear(Year)
          END IF
        
          FUNCTION = Day
        
          DATA 000, 031, 059, 090, 120, 151
          DATA 182, 212, 243, 273, 304, 334
        
          FUNCTION = Day                                         'RETURN Day number for the year
        
        END FUNCTION            
        '
        '
        '
        FUNCTION fDays2YMD ALIAS "fDays2YMD" (BYVAL Days  AS LONG, _
                                                    Year  AS LONG, _
                                                    Month AS LONG, _
                                                    Day   AS LONG  ) EXPORT AS LONG
        
          DIM DoW  AS LOCAL LONG
          DIM Temp AS LOCAL LONG
        
          DoW  = (Days MOD 7)
          Days = Days + %DateOffset
          Year = (Days \ 365)
          Temp = (Year \ 4) - (Year \ 100) + (Year \ 400)
          Days = (Days MOD 365) - Temp
        
          WHILE Days < 1
            Days = Days + 365 + fLeapYear(Year)
            DECR Year
          WEND
        
          INCR Year
        
          Julian2MD Year, Days, Month, Day
        
          FUNCTION = DoW
        
        END FUNCTION           
        '
        '
        '
        FUNCTION fYMD2Days ALIAS "fYMD2Days" (BYVAL Year  AS LONG, _
                                              BYVAL Month AS LONG, _
                                              BYVAL Day   AS LONG  ) EXPORT AS LONG
        
          DIM DoM AS LOCAL LONG
        
          IF ( Year  = 0 )   OR _
             ( Month = 0 )   OR _
             ( Day   = 0 ) THEN EXIT FUNCTION
        
          IF Month > 1 THEN Day = fJulianDay(Year,Month,Day)     'compute Julian day
          DECR Year                                              'don't count 'this year'
          Day = Day + (Year * 365) + _                           ' add full years
                      (Year \   4) - _                           ' add a day for each olympiad
                      (Year \ 100) + _                           ' subtract a day for each century
                      (Year \ 400)                               ' add a day for each epoc
                                                                 '
          FUNCTION = Day                                         'RETURN day count
                                                                 '  unREM to use WORDs
        END FUNCTION
        ------------------
        C'ya
        d83
        C'ya
        Don

        http://www.ImagesBy.me

        Comment


        • #5
          Michael,

          Do you realize Peter's posting contains three files - one to be compiled
          as a DLL, one as a header.inc and the third a simple exe? I used PB7 and it
          seemed to run all fine.

          David

          ------------------

          Comment


          • #6
            David,

            Try using the data - I posted above in my first post and you
            should see what I mean...


            Code:
            v1 = 1044890128 
            v2 = 32400      
            
            
            Results$ = DateAdd("s", v1-v2, "1/1/1970")

            The above code GPF'd - however, when walking it through using
            the debugger - It started to spit out heap errors in the debugger
            window!

            Currently - going through it line by line (slow process) - to
            produce the same results - only without crashing!

            addition to notes: Yes, 3 files - which I incorparted into 1.
            And so, I could walk the pb-debugger through completely - even
            with the errors - and get correct results! But I can't run the
            program without GPF'n!

            Regards
            Mike


            [This message has been edited by Michael Meeks (edited February 11, 2003).]
            mwm

            Comment


            • #7
              I see that DateAdd expects to receive an ASCIIZ value, but then goes
              on to pass this directly to functions that expect STRING values. This
              is not likely to be a happy combination, and may be the cause of the
              problem.

              ------------------
              Tom Hanlin
              PowerBASIC Staff

              Comment


              • #8
                Yes Michael I do get some errors and also some wrong results.

                There is another module I have used, apart from the API procedures. The source
                can be found in a posting in 1999 by Brent Thompson:-
                http://www.powerbasic.com/support/fo...-7-000189.html

                or do a search on DATESERIAL with author Brent Thompson

                I hope is might help

                David

                ------------------

                Comment


                • #9
                  Thanks, Tom, David,

                  David, That link look promising!

                  Regards
                  Mike

                  mwm

                  Comment

                  Working...
                  X