?
Solved

Validating two dates in ASP.net C#

Posted on 2006-10-31
5
Medium Priority
?
351 Views
Last Modified: 2012-06-27
Hello Experts,

In our Meeting schedule application, we have two date fields, Meeting Start Date/Time and Meeting End Date/Time.

How do I validate the two date/time such that, end date/time cannot be prior to StartDate/Time and StartDate time cannot be prior to currentDatetime.

DatTime is a usercontrol which contains a textbox and a reqd field validator to check null.

Thanks in advance for your help
0
Comment
Question by:rowmark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 17843470
use CompareValidator
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 800 total points
ID: 17843471
One way would be to create a custom date validator.

Here are some examples:

Writing a Custom Validator Control in ASP.NET
http://www.c-sharpcorner.com/Code/2002/May/DateCustomValidator.asp

Date Validator Custom Web Control
http://www.codeproject.com/aspnet/datevalidator.asp

Bob
0
 
LVL 10

Assisted Solution

by:jnhorst
jnhorst earned 800 total points
ID: 17843602
The DateTime class has a Subtract() method that returns a TimeSpan object.  Your code would look something like this:

DateTime start = DateTime.Parse("the date in your start textbox");
DateTime end = DateTime.Parse("the date in your end textbox");
TimeSpan diff = end.Subtract(start);

if (diff.TotalDays < 0)
{
     //... code would get here if end was earlier than start.
}

You can do the same with the start date and the current date, like this:

TimeSpan startDiff = start.Subtract(DateTime.Now);

if (startDiff.TotalDays < 0)
{
     // code would get here if the start day was before today.
}

John
0
 
LVL 6

Assisted Solution

by:Roopesh_7
Roopesh_7 earned 400 total points
ID: 17843869
hi,
if there is only reqd field validator to check null then first you need to check the enterd date is valid or not....i think better to use a client side function for that to validate date then you can doo the above stuf....
0
 

Author Comment

by:rowmark
ID: 17844340
Thank you all for your help.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question