Hello VbForum,

I`m migrating access database to vb.net. I have employee database with a few DateTimePickers, textboxes, and comboboxes

In access I have formulas in textbox's control source like this, and it works:

=DateDiff("d",txtDateofHire, txtManualDate)

So, I have trying to do also in vb.net, but NOT successfull. Maybe my aproach to write a code is wrong.
Anyway, I have write like this:

me.txtDayCalculation.text = DateDiff("d",txtDateOfHireDateTimePicker, txtManualDateDateTimePicker)


Please someone to check code, and give me corrections
Thank you in advance for help to anyone.

Edited 5 Years Ago by __avd: Added [code] tags.

You didn't mention where the dates come. From the textboxes or from the datetimepickers. This snippet takes first a date from a picker and then from a textbox

Dim a As Long
a = DateDiff("d", DateTimePicker1.Value.Date, TextBox1.Text)

If you use just DateTimePicker1.Value instead of DateTimePicker1.Value.Date you get a bit different result.

I would also check that the dates are valid:

Dim TempDate1 As Date
If Date.TryParse(TextBox1.Text, TempDate1) Then
  ' Datediff
  ' Not a valid date value
End If

Last thing to notice is that DateDiff function returns Long, not an Integer.



The idea of datediff function is to determine how many specified time intervals exist between two date/time values. Are you using two datetimepicker or 1 datetimepicker and a textbox?

If your using two datetimepicker, then try the code of Mr. teme64 by using


Let us know if this answers your question.

Edited 5 Years Ago by kruxena: n/a

Thank you to all for tips, help, and so quick replies.
Thank you Kruxena for Value.Date :-)

DateDiff(DateInterval.Day,DateTimePicker1.Value.Date, DateTimePicker2.Value.Date

Edited 5 Years Ago by dejanc: n/a

This question has already been answered. Start a new discussion instead.