0

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.

Edited by __avd: Added [code] tags.

3
Contributors
3
Replies
7
Views
6 Years
Discussion Span
Last Post by dejanc
0

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

0

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.

Edited by kruxena: n/a

0

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 by dejanc: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.