Results 1 to 5 of 5

Thread: Calculating between 2 dates

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    6

    Talking Calculating between 2 dates

    Hi everyone,
    i'm working with msaccess forms.
    I have 2 dates: date1 - date2
    For example, date1= #01/01/2003# and date2= #03/01/2004#
    I used dateresult= -datediff("y",[date2],[date1]) and it's just gives me dateresult = 1
    I want to get as a result the number of years, the number of months and number of days.
    Please I need your help.

    Sorry for my bad english!

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    how about

    years = datediff("yyyy",date1,date2)
    months = (years * 12) - datediff("m",date1,date2)

    I'm not sure about the days

  3. #3
    Member
    Join Date
    May 2003
    Posts
    59
    VB Code:
    1. Years  = DateDiff("yyyy", Date1, Date2)
    2. Months = DateDiff("m", Date1, Date2)
    3. Days   = DateDiff("d", Date1, Date2)

  4. #4
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    whats wrong with temp=Date1 - Date2? the result should be a value that expresses a time span in VB one would then take Hour(temp) Day(temp) Year(temp)...

    It's pritty much the same but I was just wondering.
    ?
    'What's this bit for anyway?
    For Jono

  5. #5
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    Wouldn't that just give you the same time amount only expressed in different units?

    It would be Years = Months = Days

    instead of

    Years + months + days

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