Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get date difference in VB.NET

Tags:

vb.net

I want to get the difference between two dates chosen by two date time pickers in years, months & days in separate text boxes.

I've tried:

txtyrs.text = datediff(datetimepicker1,datetimepicker2)

It is not working.

like image 635
ghost21blade Avatar asked Dec 17 '13 13:12

ghost21blade


1 Answers

Try this:

Dim date1 As Date = Date.Now
Dim date2 As Date = date1.AddDays(4.0#)

Dim span = date2 - date1

Dim days As Double = span.TotalDays '=4

And if you want to extract the years, take a look at this post.

like image 171
Bjørn-Roger Kringsjå Avatar answered Oct 13 '22 01:10

Bjørn-Roger Kringsjå