DateTime

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

Guest

If you have a text input field and you place a "comparevalidator" to ensure
that the field contains a date.... is there a method which allows you to
easily convert this into a date?

If I use the DateTime constructor, I have to pass the Year/Month/Day to the
constructor, but the CompareValidaror will accept a variety of different
formats for date so you are not quite sure where the parts of the date really
are. Do I have construct something which will parse the text field and find
the Year/Month/Day or is there and easier way?

Thanks in advance for your assistance!!!
 
Jim said:
If you have a text input field and you place a "comparevalidator" to
ensure that the field contains a date.... is there a method which
allows you to easily convert this into a date?

If I use the DateTime constructor, I have to pass the Year/Month/Day
to the constructor, but the CompareValidaror will accept a variety of
different formats for date so you are not quite sure where the parts
of the date really are. Do I have construct something which will
parse the text field and find the Year/Month/Day or is there and
easier way?

Thanks in advance for your assistance!!!

myDateVariable = CDate(myStringVariable)
 
Set the Type property of the CompareValidator to Date and you won't have
to perform the conversion yourself. I'd suspect the conversion to a date
type by the validator would be done with the current locale settings.
 
If I well remember, you should try:

DateTime myDate = DateTime.Parse(txtDate.Text);
 
Back
Top