By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,635 Members | 2,243 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,635 IT Pros & Developers. It's quick & easy.

Calculating days from dates

P: n/a
Hi

How can I calculate days from the two dates entered in date time picker
fields on winform by a user?

Thanks

Regards


Sep 28 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
John,

You first have to define what is a day.

For some people is it just two dates, (which means that a millisecond is one
day), for others it is at the second exact.

Cor
"John" <in**@nospam.infovis.co.ukschreef in bericht
news:OK**************@TK2MSFTNGP06.phx.gbl...
Hi

How can I calculate days from the two dates entered in date time picker
fields on winform by a user?

Thanks

Regards

Sep 28 '08 #2

P: n/a
You should use DateTime.Subtract to get a timespan, and then totaldays, as
in this example:

Module Module1

Sub Main()
Dim dt1 As New DateTime(2008, 9, 11)
Dim dt2 As New DateTime(2008, 9, 15)

Console.Out.WriteLine("Days: " & dt2.Subtract(dt1).TotalDays())
Console.In.ReadLine()
End Sub

End Module
"John" <in**@nospam.infovis.co.ukwrote in message
news:OK**************@TK2MSFTNGP06.phx.gbl...
Hi

How can I calculate days from the two dates entered in date time picker
fields on winform by a user?

Thanks

Regards

Sep 28 '08 #3

P: n/a
On Sep 28, 6:51*pm, "John" <i...@nospam.infovis.co.ukwrote:
Hi

How can I calculate days from the two dates entered in date time picker
fields on winform by a user?

Thanks

Regards
Assuming you have 2 DateTimePicker controls, you can use substract
method to get result as string:

'Calculate DateTimePicker1 - DateTimePicker2
'-----Begin-----
Dim str As String
str = DateTimePicker1.Value.Date.Subtract _
(DateTimePicker2.Value.Date).Days.ToString()
'Show difference in message box
MsgBox(str)
'-----End------

Hope this helps,

Onur Güzel
Sep 28 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.