Calculating days from dates

J

John

Hi

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

Thanks

Regards
 
C

Cor Ligthert[MVP]

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
 
F

Family Tree Mike

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
 
K

kimiraikkonen

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
 
J

jano

Hi John and all!

I found this:
http://www.bizsupportonline.net/infopath2007/calculate-date-difference-infopath-rules-formulas.htm

but it didn't work for me:((

note:
when I entered the functions: number, substring and floor; and clicked on
'verify formula', the infopath displayed Error indicating that there
shouldn't be any spaces between numbers 'startDate, 9, 2' etc.
So, I repaired the formulas deleting all spaces between numbers, but it
still didn't work after that.

I'm starting to believe that there is no other way to do this than code,
which I'm trying to avoid. So any ideas would be greatly appreciated.

thx,
jano
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top