Page 1 of 1

Adding 6 Months to the current date

Posted: Mon Feb 15, 2016 3:38 pm
by FMOH
Hi I am currently evaluating Ranorex. I have downloaded the Trial Version. I have recorded a test and in the test I have to add Departure Date and Return Date. I want to automatically calculate the Departure date by adding 180 days to current date and for the Return date add 182 Days to current Date. Can you please let me know how best to achieve this.

Departure Date:
<input name="ctl00$cphM$txtDepartureDate" type="text" value="16/02/2016" maxlength="10" id="ctl00_cphM_txtDepartureDate" autocomplete="off" onchange="DateChanged(this,0)" onkeydown="return DateKeypressCheck(event);" style="font-family:Arial;width:90px;" class="hasDatepicker">

Return Date:
<input name="ctl00$cphM$txtReturnDate" type="text" value="16/02/2016" maxlength="10" id="ctl00_cphM_txtReturnDate" autocomplete="off" onchange="DateChanged(this,1)" onkeydown="return DateKeypressCheck(event);" style="font-family:Arial;width:90px;" class="hasDatepicker">


The Ranorex Version is 5.4.4.26486

Thanks

Re: Adding 6 Months to the current date

Posted: Wed Feb 17, 2016 9:40 am
by odklizec
Hi,

Below sample code should help you with generating date string with actual date + 180(182) days and setting the obtained date strings to departure/return inputs.

Code: Select all

string dateFormat = "dd/MM/yyyy";
int addDepartureDays = 180;
System.DateTime departureDate = System.DateTime.Today;  //get actual date
departureDate = departureDate.AddDays(addDepartureDays);  //add number of days to actual date

int addReturnDays = 182;
System.DateTime returnDate = System.DateTime.Today;  //get actual date
returnDate = returnDate.AddDays(addReturnDays);  //add number of days to actual date

//convert departure/return date to string
string departureDateStr= departureDate.ToString(dateFormat);  
string returnDateStr= returnDate.ToString(dateFormat);

repo.DepartureInput.PressKeys(departureDateStr); //set departure date to departure input
Delay.Duration(100);
repo.ReturnInput.PressKeys(returnDateStr);
//set return date to return input
Delay.Duration(100);
Please take this code as a sample! I did not test it, so it may need some additional enhancements/corrections. Hope this helps?