Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am using 2 datetimepicker.

1) any date select from first datetimepicker.

2) then another one date is select from second datetime picker.

my request is: the second datetimepicker selecting date only accept after first date.
how to compare from first date and second date.

EXAMPLE:

i.e) first selected date is 10/10/2011 ok.

then second datetimepicker selecting date accept only after first date i.e 11/10/2011

but can not accept before date that is 09/10/2011.
Posted
Updated 16-Oct-11 23:11pm
v2
Comments
uspatel 17-Oct-11 5:12am    
Retaged from HTML to C#

Or, you can try this: DateTime.Compare[^]

Nice and clean :) hope this helps

Cheers...
 
Share this answer
 
C#
private void dateTimePicker1_ValueChanged(...)
{
dateTimePicker2.Value = DateTimePicker1.Value.AddDays(1);
}

private void dateTimePicker2_ValueChanged(...)
{
       if(dateTimePicker2.Value < DateTimePicker1.Value)
       {
         MessageBox.Show("Cannot be less than previous date");
         dateTimePicker2.Value = DateTimePicker1.Value.AddDays(1);
       }
}


Edit: Please Check my updated solution
 
Share this answer
 
v3
Comments
lukeer 17-Oct-11 5:26am    
That wouldn't prevent User from selecting an earlier date on dateTimePicker2 afterwards.
Praveen Kullu 17-Oct-11 5:32am    
@Lukeer Thanks for pointing it out, I have updated the solution
Use Compare validater

XML
<asp:CompareValidator ID="CompareValidator1" runat="server"  ControlToValidate="txtenddate"
ErrorMessage="End Date is not less than Start Date" Operator="GreaterThanEqual" Type="Date" Text="*" ControlToCompare="txtstartdate"></asp:CompareValidator>
 
Share this answer
 
 
Share this answer
 
Comments
lukeer 17-Oct-11 5:25am    
5 for ease of use.
[no name] 17-Oct-11 11:57am    
+5 Simple and with MSDN reference :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900