Setting the date to one day previous

Ask general questions here.
mghali
Posts: 26
Joined: Fri Jul 18, 2014 9:05 pm

Setting the date to one day previous

Post by mghali » Fri Apr 10, 2015 5:20 pm

I have a date field. I am trying to set the date to the previous date on any give date.
the C# code for this would be eqivalent to:

DateTime startDate = Datetime.Now;

Console.WriteLine(startDate.AddDays(-1).ToShortDateString);
Console.ReadLine();

so if the date today is 5/15/2014 then the date set should be 5/14/2014

This date has to be set to the element startDate with the xpath

(.//tabpage[@title~'^VERC-23451\ -\ Williams,\ Wa' and @controltypename='TabPage']/?/?/container[@controltypename='SplitContainer']/container[2]/?/?/tabpage[@title~'^Procedure:\ MCT\ 4/10/2015\ ' and @controltypename='TabPage']/container/container[@controltypename='Panel']/container[@controltypename='Panel']/container[@controltext='Procedure Information']/datetime[@controltypename='DateTimePicker']/?)

The Date TimePicker has to read the value of yesterday's day.

The errors that I get are

(1) The type or namespace name 'Datetime' does not exist in the namespace 'System' (are you missing an assembly reference?) (CS0234) - C:\Users\BeaconUser\Documents\Ranorex\RanorexStudio Projects\Patients\Patients\NewPatientFile.UserCode.cs:44,45

(2) Ranorex.Unknown' does not contain a definition for 'set' and no extension method 'set' accepting a first argument of type 'Ranorex.Unknown' could be found (are you missing a using directive or an assembly reference?) (CS1061) - C:\Users\BeaconUser\Documents\Ranorex\RanorexStudio Projects\Patients\Patients\NewPatientFile.UserCode.cs:45,47

Please Help

Thank you!!!
You do not have the required permissions to view the files attached to this post.
Last edited by mghali on Fri Apr 10, 2015 7:46 pm, edited 1 time in total.

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Setting the date to one day previous

Post by krstcs » Fri Apr 10, 2015 7:15 pm

I think you have the code correct. What isn't working?


If you are asking how to do it without code in Ranorex Studio, then that isn't possible directly. You will need to create a usercode method that performs the calculations and validation.


Also, in the future please include the following information as it will help us better understand your situation:
1. Ranorex version (5.3.1 is current)
2. Windows version and bit-ness (x86 vs x64)
3. Any error messages (if applicable)
Shortcuts usually aren't...

mghali
Posts: 26
Joined: Fri Jul 18, 2014 9:05 pm

Re: Setting the date to one day previous

Post by mghali » Fri Apr 10, 2015 7:32 pm

How to display as a set value for a repository item called startDate?

Where should i direct the WriteLine to ?

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Setting the date to one day previous

Post by krstcs » Fri Apr 10, 2015 7:36 pm

I don't understand your issue. Can you please explain in more detail what you are trying to accomplish?


If you just want to print out the date to the report you can use a Report action in the module or in user code. You should probably not be using Console.Writeline in Ranorex tests.
Shortcuts usually aren't...

mghali
Posts: 26
Joined: Fri Jul 18, 2014 9:05 pm

Re: Setting the date to one day previous

Post by mghali » Fri Apr 10, 2015 7:48 pm

I update my post please review it and let me know if you need anymore information.

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Setting the date to one day previous

Post by krstcs » Fri Apr 10, 2015 7:54 pm

Please do not update your posts after someone has replied to them without noting the edits. This can create confusion and misunderstandings as people reply to one thing only to have it changed to something else. (For example, you could have asked "Is the sky blue?" I would have answered "Yes." And then you changed the question to "Is Ranorex free?", which is not the question I answered.)

If others have replied to the post already you should create a new reply instead of updating in order to maintain the integrity and flow of the conversation.



As for your current errors, without also seeing the code you have written it will be impossible to tell you what is wrong. Please post the code you are using, or create a sample project that has the same issue and post it so we can look at it.
Shortcuts usually aren't...

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

Re: Setting the date to one day previous

Post by odklizec » Mon Apr 13, 2015 8:36 am

mghali wrote:I have a date field. I am trying to set the date to the previous date on any give date.
the C# code for this would be eqivalent to:

DateTime startDate = Datetime.Now;

Console.WriteLine(startDate.AddDays(-1).ToShortDateString);
Console.ReadLine();

The errors that I get are

(1) The type or namespace name 'Datetime' does not exist in the namespace 'System' (are you missing an assembly reference?) (CS0234) - C:\Users\BeaconUser\Documents\Ranorex\RanorexStudio Projects\Patients\Patients\NewPatientFile.UserCode.cs:44,45
I think you should fix Datetime.Now; to DateTime.Now;
DateTime startDate = DateTime.Now;

As for the other error, could you post the failing code (from NewPatientFile.UserCode.cs:45,47)?
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