Results 1 to 14 of 14
  1. #1
    Join Date
    Jun 2004
    Posts
    7

    Unanswered: DateDiff Problem

    Hi,

    I'm using microsoft access 2000. Can any1 tell me what's e syntax for findin e number of weeks between date 1 and date 2? is it DateDiff("wk", "date1", "date2") kind of having some troubles with this.

    Thankz.

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Try this.......


    MsgBox DateDiff("w", theNewerDate, theOlderDate)

  3. #3
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    Quote Originally Posted by CyberLynx
    Try this.......


    MsgBox DateDiff("w", theNewerDate, theOlderDate)
    it should be "ww" instead "w" I think.
    ghozy.

  4. #4
    Join Date
    Jun 2004
    Posts
    7
    hmm.. stil doesnt works for me. Actually, I'm using a form to get the values of the 2 dates and i'm supposed to calculate the number of weeks between the two dates. I've created a query but i'm not sure how to update the results automatically to the main table after the dates are entered in the form.

  5. #5
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Lightbulb

    DateDiff("ww","20.07.2003", "28.07.2003") result in 1

    When you are using a form then use

    Forms("yourFormName").txtWeekstxtWeeks=DateDiff("ww",Forms("yourFormName").txtyourDate1, Forms("yourFormName").txtyourDate2)

    Where txtWeeks is your text box where the number of weeks will be calculated.

  6. #6
    Join Date
    Jun 2004
    Posts
    7
    This is to b coded in VBA or in access itself? I tried in VBA but it doesnt seems like it's workin..

    Quote Originally Posted by hammbakka
    DateDiff("ww","20.07.2003", "28.07.2003") result in 1

    When you are using a form then use

    Forms("yourFormName").txtWeekstxtWeeks=DateDiff("ww",Forms("yourFormName").txtyourDate1, Forms("yourFormName").txtyourDate2)

    Where txtWeeks is your text box where the number of weeks will be calculated.

  7. #7
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Lightbulb

    This code should run under Access.
    You have to change "yourFormName" with your actual form name where your text boxes are.

    Also replace txtyourDate1 with the name of your textbox where you enter the first date
    Also replace txtyourDate2 with the name of your textbox where you enter the second date

  8. #8
    Join Date
    Jun 2004
    Posts
    43
    Txtoutput = DateDiff("m", DateOpened, Date())

    where txtoutput is texbox to diplay result

  9. #9
    Join Date
    Jun 2004
    Posts
    7
    Hi, in which part of e program should i place e codes? cos i've replace e txt n form name n place e code under the properties of e txtfield that has to calculate the datediff function.

    Sorry for so much troubles cos i'm not very familar with microsoft access.

    Quote Originally Posted by hammbakka
    This code should run under Access.
    You have to change "yourFormName" with your actual form name where your text boxes are.

    Also replace txtyourDate1 with the name of your textbox where you enter the first date
    Also replace txtyourDate2 with the name of your textbox where you enter the second date

  10. #10
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Here is a simple example hope it helps you
    Attached Files Attached Files

  11. #11
    Join Date
    Jun 2004
    Posts
    7
    Hi,
    Thankz! It's very helpful! Last question: Is there a way to record the number of weeks into a table? There's no control source for label..

    Thank you very much!
    Quote Originally Posted by hammbakka
    Here is a simple example hope it helps you

  12. #12
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    You can change the lable to a text box then bound it to your table.
    Or
    Use the Caption event of the lable to store what in the lable to the table

  13. #13
    Join Date
    Jun 2004
    Posts
    7
    IT WORKS!!!! THANK YOU VERY MUCH!!!! IT FINALLLY WORKS! HAHA! MILLION OF THANKZ!

    Quote Originally Posted by hammbakka
    You can change the lable to a text box then bound it to your table.
    Or
    Use the Caption event of the lable to store what in the lable to the table

  14. #14
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Glad that it works
    Good luck

Posting Permissions

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