Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2004
    Posts
    287

    Unanswered: Caulcating Time from Data/Time

    Is there an easy way to calculate days and time (either or both) from two date fields so I can use it in my reports and on my forms?

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Have a look at the DateDiff function in your help screen

    DateDiff("d",#1/1/07#,#2/7/07#) is 37 days
    Inspiration Through Fermentation

  3. #3
    Join Date
    Mar 2004
    Posts
    287
    thanks, but i thought of that but 6/2/07 to 7/2/07 states there is 29 days so something is wrong?

    My date includes date and time so it would be good to state how many hours (do not need days really, just hours) between dates?

  4. #4
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Not sure about the first problem...
    If I run
    SELECT DateDiff("d",#6/2/2007#,#7/2/2007#) AS Expr1
    I get 30 days.

    Again, look at BOL. You can search for differences in hours, seconds, years, etc
    Inspiration Through Fermentation

  5. #5
    Join Date
    Mar 2004
    Posts
    287
    thanks i got it to work, i just done it via hours and the problem was that my date only had date not time so for some reason it was erroring with the # of days... just out of interest how do i make it so if i punch in 1/1 for 1st january that it will automatically put the time after it (general date format)

    Also, I have a datecheck that says good morning or good afternoon depending on the time, but this does not work (just says good morning all the time) - any idea's how i would get it to check the time now() is more then 12:00 etc etc

    If DateCheck <= "1159" Then doesn't work???
    Thanks.

  6. #6
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    I think you want to use DatePart for that
    Inspiration Through Fermentation

Posting Permissions

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