Adding 6 Months to the current date

Ask general questions here.
Posts: 1
Joined: Mon Feb 15, 2016 3:20 pm

Adding 6 Months to the current date

Post by FMOH » Mon Feb 15, 2016 3:38 pm

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


User avatar
Ranorex Guru
Ranorex Guru
Posts: 6781
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Adding 6 Months to the current date

Post by odklizec » Wed Feb 17, 2016 9:40 am


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
//set return date to return input
Please take this code as a sample! I did not test it, so it may need some additional enhancements/corrections. Hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration