Results 1 to 5 of 5

Thread: Date Difference Commputing

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 1999
    Location
    Zagreb, Croatia
    Posts
    2

    Post

    Please help Me!
    I'm Programmer beginner and I use VB6. Here is mine problem.
    I set following variables:
    Date1 - presenting current date in format "dd.mm.yyyy."
    Date2 - presenting end date also in format "dd.mm.yyyy."
    Date3 - presenting difference between current date and end date
    Wenn I use relationship Date3 = Date2 - Date1 in order to calculate difference between 15.12.1999. and 05.01.2000. I get negative number (-10). Same situation is wenn I use Date3 = DateDiff("d", Date1, Date2).
    What must I do to get correct date difference?
    Thank You!

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    The code you have posted seems to be correct for me. Are you sure that date1 is the earlier date than date2? Because for me the only way to get negative number is to calculating time from now to the past.

    ------------------
    Visual Basic Programmer
    ------------------
    PolComSoft
    You will hear a lot about it.


  3. #3
    Lively Member
    Join Date
    Dec 1999
    Location
    Karlsruhe, Germany
    Posts
    122

    Post

    Hi,

    I didn't quite understand your problem, but this works:

    Code:
    Dim Date1 As Date
    Dim Date2 As Date
    
    Date1 = DateValue("15.12.1999")
    Date2 = DateValue("05.01.2000")
    
    MsgBox DateDiff("d", Date1, Date2)
    MsgBox Abs(DateDiff("d", Date2, Date1))
    RogerH

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    What regional settings are you using?
    I see from your profile that you live in Croatia. I set my PC to Croatian settings and the only date format suggested is yyyy.MM.dd or yy.MM.d for short date and yyyy.MMMM.dd for long date.

    When using dates it's best to make sure that the values you enter match the regional settings.

    15.12.1999 can only be 15th December
    whereas
    05.01.2000 could be 5th January or 1st of May depending on your regional settings

    However, the following code works ok on Croatian settings

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim Date1 As Date
    Dim Date2 As Date
    Dim date3 As Integer
    
    Date1 = "1999.12.15"
    Date2 = "2000.01.05"
    
    date3 = DateDiff("d", Date1, Date2)
    
    End Sub
    ------------------
    Mark Sreeves
    Analyst Programmer

    [email protected]
    A BMW Group Company

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 1999
    Location
    Zagreb, Croatia
    Posts
    2

    Post

    Thank You Guy to all.
    Happy New Year!

    ------------------

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