Results 1 to 8 of 8

Thread: Dates

  1. #1

    Thread Starter
    Hyperactive Member tomjess's Avatar
    Join Date
    Mar 2001
    Location
    Hamilton, New Zealand
    Posts
    348

    Dates

    Hi Guys

    This has been thrashed around many a time I suppose, but here goes.

    I have two text boxes, text1 and text2 both have a date in them. I would like to find out the difference in days from on to the other, i.e.

    text1 = 20/2/2005 and text2 = 22/2/2005 and its 2 days.

    Thanks in advance

  2. #2

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Dates

    I just typed in a whole page of syntax for this. Its on the same page.

    My date format is different, so I had to use this:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim a As Integer
    5. a = DateDiff("d", "2/20/05", "2/22/05")
    6. MsgBox a
    7. End Sub

    It depends on the computer date format.

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Dates

    Quote Originally Posted by dglienna
    ... It depends on the computer date format.
    Not really - as long as it is date in any format regardless of your systems settings.
    Try this and you will get True for each line returned:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Debug.Print IsDate("19/02/05")
    3.     Debug.Print IsDate("02/19/05")
    4.     Debug.Print IsDate("19 feb 2005")
    5.     Debug.Print IsDate("19/feb/05")
    6.     Debug.Print IsDate("feb/19/2005")
    7. End Sub
    You may also try many6 other different formats but as long as it is DATE ...

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Dates

    VB Code:
    1. a = DateDiff("d", "20/2/05", "22/2/05")
    2. MsgBox a

    I typed that in, and it returned 731 days.

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Dates

    VB Code:
    1. a = DateDiff("d", now, "22/2/05")
    2. MsgBox a

    I typed that in, and it returned 6195 days.

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Dates

    You made me think for a few seconds ... I'm afraid it could be a bug in DateDiff ... What happends is it converts "20/2/05" t0 "2/5/2020". You can get that by replacing quotes with pound sign and VB automatically outputs this: #2/5/2020# . That is why you got 731 days which is 2 years. So I guess year better be formatted as 4 digits.

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Dates

    That makes sense. I thought it was the internal date format, but that works as well.

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