Results 1 to 20 of 20

Thread: DataDiff & DateAdd

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132

    Unhappy

    How do you implement the DateDiff and DateAdd commands in Access 97?
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  2. #2
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696

    Question

    Hi Harrild

    Do you mean in VBA for access or in SQL

    Ian
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    A SQL would be good plz...
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  4. #4
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696

    Smile

    Try this for size

    SELECT DATEDIFF(day, date1, column1) AS no_of_days
    FROM table1



    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    Ok its a start but i want the date fidd between todays date and the one in the column...
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  6. #6
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    Hi

    In that case use

    SELECT DATEDIFF(day, getDate(), column1) AS no_of_days
    FROM table1





    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    huh?
    I still have no idea on how to use it.....what are 'day', 'getdate()' and 'column1'?
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  8. #8
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    Hi harry

    Sorry about he delay in reurning bit iv'e been away for the weekend

    The datediff function returns the difference in the specified format between two dates. Datediff(datepart,date1,date2). SO in the example I gave you it would return a column called no_of_days consisting of the number of days between today (getdate()) and whatever date that would be in column1.

    Ian


    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    And where do i enter that then?
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    in VBA please
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  11. #11
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696

    Question

    Do You mean you want to check a date in VBA, or you want to return Something in a recordset using the datediff in SQL?

    Ian
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    i got DateAddn in VBA for a form and i want the DateDiff in VBA so i can use it with a form
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  13. #13
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    In VBA,
    all you need to do is the following

    Dim intDifferenceinDays as integer

    intDifferenceinDays = DateDiff("d",now(),somedate)

    That will return the difference in days between today(now()) And what ever date you put in the second part.

    Hope this helps

    Ian
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    could i out
    intDifferenceinDays = DateDiff("d",now(), columname)

    cos the diff is from todays date and the other column's date, which in turn gets its value from another column using DateAdd
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  15. #15
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    What do you mean by could i out ?
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    sorry i meant 'put'
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  17. #17
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    Yes you can

    There is no reason wht you can't put a DateAdd inside a DateDiff

    Ian
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    maybe you missunderstood

    can i put a column name in place of somedate()?
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  19. #19
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    Yes you can

    Code:
    intDifferenceinDays = DateDiff("d",now(), myrecordset("Mydatecolumn"))
    Ian

    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    thanks i let you know how it goes in about 12-24hrs cos the DB is at school at the mo
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

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