[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Validating two dates in ASP.net C#

Posted on 2006-10-31
5
Medium Priority
?
359 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

656 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