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:

txtDayCalculation
=DateDiff("d",txtDateofHire, txtManualDate)
txtYear
=Int(txtDayCalculation/365)
txtMonth
=Int((txtDayCalculation-(txtYear*365))/30) 
txtDay
=((txtDayCalculation-txtYear*365))-(txtMonth*30).

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.

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
Else
  ' Not a valid date value
End If

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

HTH

Hi...

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

datetimepicker.value.date

.
Let us know if this answers your question.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.