Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Warrington, Cheshire
    Posts
    355
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Date calculations as part of sql in .net (.net)

    In a select statement I want to caluclate the number of days between two events.
    The trans date (a field in my table) and the chosen date (for the time being I am using Now() to test)
    My statement contains the following:
    <pre>"(" & Now() & "-tbl_SalesTransactions.Due_Date) as DaysOver, "</pre>


    but I don't get the right answer.
    I've used
    <pre>"(DateDiff('d',tbl_SalesTransactions.Due_Date ," & today() & ")) as DaysOver, "</pre>


    but again no success and the output was in the Due_Date date in number format (e.g. -37489 etcetera)

    Any suggestions?

    TIA
    Alan

  2. #2
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Warrington, Cheshire
    Posts
    355
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Date calculations as part of sql in .net (.net)

    Again, is there something magical about the Lounge.
    I only have to post a query and moments later, inspiration or other lounge gurus drive a solution over my toe....

    Following works fine (as I should have realised earlier when using dates I need to include hashes)
    <pre>"(#" & Now() & "#-tbl_SalesTransactions.Due_Date) as DaysOver, "</pre>


    Cheers
    Alan

  3. #3
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date calculations as part of sql in .net (.net)

    Wow! You just answered my question, too! I've been trying to do something like this for a few days and just gave up, but now I can go onward and upward. <img src=/S/hailpraise.gif border=0 alt=hailpraise width=27 height=22>
    Carpy Diem, it&#39;s .

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Date calculations as part of sql in .net (.net)

    That only works if you are running it on an Access backend. If the backend is SQL Server, you have to use single quotes to delimit the date, not hash marks.
    Charlotte

Posting Permissions

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