DateDiff Function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DumStudent
    New Member
    • Feb 2007
    • 1

    #1

    DateDiff Function

    I need help with what to write for my DateDiff Function to work properly between two datetimepicker boxes to give 'days' results. This is what I have and it works except I can't have the intDate1 to be specific and intDate2 as Now. I need to make it work so when the second date is chosen it gives the days between current date in intDate1 and date selected in intDate2.

    Help Please??

    Code:
      Dim intDiff As Integer
            Dim intDate1 As String
            Dim intDate2 As String
            intDate1 = "01/01/2007"
            intDate2 = "Now"
            intDiff = DateDiff("d", "01/01/2007", Now())
            TxtBox1Days.Text = intDiff
    Last edited by willakawill; Feb 17 '07, 06:01 PM. Reason: please use code tags when posting code
  • samycbe
    New Member
    • Feb 2007
    • 83

    #2
    Dear Friend.

    Step1 : Create 1 datepicker and one 1 command button in a form
    step 2 : select any date in datepicker1
    step 3 : write following code in command1_click

    Dim a As Double
    a = DateDiff("d", DTPicker1, Date)
    MsgBox a

    is it ok

    samy

    Comment

    • PadminiJ
      New Member
      • Mar 2007
      • 1

      #3
      Use CDate(string) function to convert string to date.

      Padmini.

      Comment

      • vijaydiwakar
        Contributor
        • Feb 2007
        • 579

        #4
        Originally posted by DumStudent
        I need help with what to write for my DateDiff Function to work properly between two datetimepicker boxes to give 'days' results. This is what I have and it works except I can't have the intDate1 to be specific and intDate2 as Now. I need to make it work so when the second date is chosen it gives the days between current date in intDate1 and date selected in intDate2.

        Help Please??

        Code:
          Dim intDiff As Integer
                Dim intDate1 As String
                Dim intDate2 As String
                intDate1 = "01/01/2007"
                intDate2 = "Now"
                intDiff = DateDiff("d", "01/01/2007", Now())
                TxtBox1Days.Text = intDiff
        just try this with one change as
        Code:
         
        Dim intDiff As Integer
        dim intDiff%
                intDiff = DateDiff("d", dtp1.value, dtp2.value)
                TxtBox1Days.Text = intDiff

        Comment

        Working...