Comparing two date times

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

Guest

Hello,

I have two texboxes txtStart and txtEnd. User will pick startdatetime and
enddatetime from the calendar picker.

The datetime format will always be 11-02-2006 02:30 PM.

I am trying to create a custom Validator control to validate few conditions
like startdate cannot be less than end date. and Start Date cannot be less
than currentdate time etc.

I dont want to do any clientsite validations for this. How do I make sure
that it validates properly. I havent worked on custom validators till date.

Please help
 
If you are doing it server side, you can do something like so:

protected Button1_Click(object sender, EventArgs e)
{
if(IsValid())
{
//Send user to confirmation
}
else
{
//Send user back to form?
}
}

private bool IsValid()
{
bool valid = true;

DateTime startDate = DateTime.Parse(txtStartDate.Text);
DateTime endDate = DateTime.Parse(txtEndDate.Text);

if(endDate < startDate)
valid = false;

return valid;
}

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
 
Back
Top