Convert string to DateTime and compare with another????

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two text boxes;

startTimeTextBox.Text = "08:00";
endTimeTextBox.Text = "15:00";

and now I will check if startTimeTextBox.Text starts
really before endTimeTextBox.Text

something like this:


bool timeIsOk = (startTimeTextBox.Text < endTimeTextBox.Text);


but how to do it real?



regards,

gicio
 
use this function:
DateDiff(DateInterval.Minute, CDate(startTimeTextBox.Text ),
CDate(endTimeTextBox.Text))
 
Hi,

You can use DateTime's Parse and ParseExact methods to convert the strings
to DataTime instances and then compare the created instances as usual.
 
thx!

but I can't find any DateDiff function in the .NET framework.
from wich namespace is DateDiff ???

regards,


gicio
 
Those functions are visual basic functions - and although you might be able
to use them from C#, a better way would be something like:

DateTime time1 = Convert.ToDateTime( startTimeTextBox.Text );
DateTime time2 = Convert.ToDateTime( endTimeTextBox.Text );

if ( time1 < time2 )

Note: I didn't consult the API when writing this - so check out the
functions yourself ( which I would recommend you do anyway to get familiar
with them ).

Pete
 
Back
Top