Results 1 to 5 of 5

Thread: DateDiff problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 1999
    Posts
    309

    DateDiff problem

    In Authorware there is the function "DateToNum" here are the specifications:

    number := DateToNum(day; month; year)
    DateToNum converts a date (day, month, and year) to a number that corresponds to the number of days since January 1, 1900. This function performs the opposite calculation from the Date function, which converts a number to a date. The following table shows the range of valid dates:
    Windows: 1, 1, 1970, to June, 2, 2036 (25568 to 49709)
    Macintosh: 1, 1, 1904, to June, 2, 2040 (1461 to 51171)

    I tried to code it in vb (asp actually) but it is not the same :

    function DateToNum(dtDate)
    dim strStartDate, dtStartDate
    strStartDate = "January 1, 1900"
    dtStartDate = DateValue(strStartDate)
    DateToNum = DateDiff("d",dtStartDate,dtDate)
    end function

    1/1/1970 produces 25568 in authorware but 25567 in my routine.

    How can I make the routine work for me ?

  2. #2
    Hyperactive Member DKCK's Avatar
    Join Date
    Dec 2000
    Location
    United States
    Posts
    329
    DateToNum = DateDiff("d",dtStartDate+1,dtDate)

  3. #3
    nullus
    Guest

    Smile

    try this:

    VB Code:
    1. Private Sub Command1_Click()
    2.     MsgBox DateToNum("01/01/1970")
    3. End Sub
    4.  
    5. Public Function DateToNum(pDate As Date) As Long
    6.     Dim lngDate As Long
    7.    
    8.     lngDate = pDate
    9.    
    10.     DateToNum = lngDate
    11. End Function

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 1999
    Posts
    309
    Both solutions do not produce equivalent output. I converted nullus's routine to asp:

    function DateToNum(dtDate)
    Dim lngDate
    lngDate = CLng(CDate(dtDate))
    DateToNum = lngDate
    end function

    however this gives me 25569 for 1/1/1970, while the authorware routine returns 25568.
    inserting "June 2, 2036" returns 49828 while in authorware it returns 49709.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 1999
    Posts
    309
    It works... Authorware goes beserk out of the bounds of 1970, 2036.. Here's my code :

    function DateToNum(dtDate)
    Dim lngDate
    lngDate = CLng(CDate(dtDate))
    DateToNum = lngDate-1
    end function

    function NumToDate(lngNumDate)
    dim dtDate
    dtDate = Cdate(CLng(lngNumDate))
    NumToDate = dtDate+1
    end function

    Response.Write DateToNum("September 5, 2002")
    Response.Write "<br />"
    Response.Write NumToDate(37503)

Posting Permissions

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



Click Here to Expand Forum to Full Width