Pages

Search This Blog

Monday, July 19, 2010

How to store date in dd-mm-yy format in Selenium

There are some cases while we search the data based on start and end date based on date format dd-mm-yy.

=======

<tr>
<td>store</td>
<td>javascript{var d = new Date();var curr_date = d.getDate()-2;if(curr_date.toString().length!=2) curr_date = '0'+curr_date ;var curr_month = d.getMonth(); curr_month = curr_month + 1;if(curr_month.toString().length!=2) curr_month= '0'+curr_month;curr_date + '-'+ curr_month + '-'+10;}</td>
<td>start_date</td>
</tr>
<tr>
<td>store</td>
<td>javascript{var d = new Date();var curr_date = d.getDate();if(curr_date.toString().length!=2) curr_date = '0'+curr_date ;var curr_month = d.getMonth(); curr_month = curr_month + 1;if(curr_month.toString().length!=2) curr_month= '0'+curr_month;curr_date + '-'+ curr_month + '-'+10;}</td>
<td>end_date</td>
</tr>
<tr>
<td>echo</td>
<td>${start_date}</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${end_date}</td>
<td></td>
</tr>


This gives the result in below format
Start date : 17-07-10
End date : 19-07-10