This is a migrated thread and some comments may be shown as answers.

Date verification (today)

2 Answers 171 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lukas
Top achievements
Rank 1
Lukas asked on 08 Jun 2011, 09:29 AM
Hello,


I have a problem to verify if the date selected in calendar (RadDatePicker) is the same like today's.
In the application is the date populated automatically and there si a period of 5 years that is represented by two calendars.

How can I verify if the dates are "today" and "today + 5 years" ?


Thank you very much, L.

2 Answers, 1 is accepted

Sort by
0
Accepted
Stoich
Telerik team
answered on 13 Jun 2011, 02:51 PM
Hi Lukas,
     you'll need a coded solution for this.

A while ago I created a video demonstrating how to implement a similar for a different customer. Check it out here:
http://screencast.com/t/HxRIHjcr
The video demonstrates the basic approach:

1) Use the Extract feature to extract the dates from your application.
2) In a coded step verify whether today's date is correct. Than add 5 years to today's date and use that to verify your second date. It will look something like this in code:
//We assume the two dates were extracted in variables Date1 and Date2 respectively
String today = (string)(System.Convert.ChangeType(Data["Date1"], typeof(string)));
String future = (string)(System.Convert.ChangeType(Data["Date2"], typeof(string)));
             
DateTime dt1;
dt = Convert.ToDateTime(today);
 
if (today == DateTime.Today) {  //Check whether date for today is correct and fail step it it's not
Log.WriteLine("Today date is correct");
} else { throw new Exception("Today date was incorrect!"); }
 
DateTime d2;
d2 = Convert.ToDateTime(future);
 
if (future ==  DateTime.Today.AddYears(5)) { //Check whether future for today is correct and fail step it it's not
Log.WriteLine("Future date is correct");
} else { throw new Exception("Future date was incorrect"); }
 

Let me know if you have any problems getting this to work.

Regards,
Stoich
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Lukas
Top achievements
Rank 1
answered on 14 Jun 2011, 09:49 AM
Hello Stoich,


thank you for the code, it worked after some cosmetical changes...
Here is the corrected code:
//We assume the two dates were extracted in variables Date1 and Date2 respectively
String today = (string)(System.Convert.ChangeType(Data["Date1"], typeof(string)));
String future = (string)(System.Convert.ChangeType(Data["Date2"], typeof(string)));
              
DateTime dt1;
dt1 = Convert.ToDateTime(today);
  
if (dt1 == DateTime.Today) //Check whether date for today is correct and fail step it it's not
Log.WriteLine("Start date is correct");
}
else
{
    throw new Exception("Start date was incorrect!");
}
  
DateTime dt2;
dt2 = Convert.ToDateTime(future);
  
if (dt2 == DateTime.Today.AddYears(5)) //Check whether future for today is correct and fail step it it's not
{
Log.WriteLine("End date is correct");
}
else
{
    throw new Exception("End date was incorrect");
}

BR, Lukas.
Tags
General Discussions
Asked by
Lukas
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Lukas
Top achievements
Rank 1
Share this question
or