Comparing two date times

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
 
C

Cowboy \(Gregory A. Beamer\)

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;
}
 

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

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top