473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Comparing two date times

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
Nov 2 '06 #1
1 1185
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!
*************************************************
"Srini" <Sr***@discussions.microsoft.comwrote in message
news:CD**********************************@microsof t.com...
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

Nov 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Javier | last post by:
Hi IŽve a routine that will read date and times in a vector of strings ie: 30/02/2005 19:20 In some moment IŽll need to check if there are in vector a date like current date with a time...
4
by: M.i.r.a.g.e. | last post by:
I am sorry if this has been asked before, but I looked all over for exactly what I need, before asking you guys. I know that it has something to do with the Date object, but I'm not sure how to...
8
by: Riegnman | last post by:
Hey guys, I'm in need of a little help. I am very new to access but have been trying to learn. My problem is as follows. . . We have time clocks that dump the badge punches into a .log file on...
2
by: Duppypog | last post by:
I'm trying to compare a date stored in a database with today's date using an If statement, but it's not returning true. Example, value in database is 11/5/2003 with today being 11/6/2003. Can...
5
by: JL | last post by:
I need to compare two times. The problem I have is this: In my code I create a time variable using the format statement below: dim firstTime as DateTime fistTime = Format("12:00:00 AM", "T") ...
6
by: Simon Harvey | last post by:
Hi everyone, I need to be able to compare to dates to ensure that one is at least 1 day greater than the other. Im trying to do if(toDate !> fromDate){ // handle }
1
by: stormcandi | last post by:
Hello all, I am creating a web page in c# to allow a user to select a date from a calendar and then enter a start and end time. The problem I am having is when I have a start time of 10:00 PM and...
3
by: Phoe6 | last post by:
I would like to parse RFC 1123 date format and compare two dates. I find that datetime module does not specifically confirms to any RFC. Any suggestions as how I can handle the RFC 1123 date...
3
by: Anil Gupte | last post by:
I am using the followig code: SqlConnection con = new SqlConnection(strcon); con.Open(); string strSelect = "Select PaidUntil from Users where username='" + un + "'"; SqlCommand cmd = new...
3
by: Brian | last post by:
I need to be able to only allow my clients to enter data into a part of a form between specific hours of the day. i can find tons of articles on comparing dates, but not times. does anyone know...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.