Get Current Date

Ask general questions here.
Robb
Posts: 6
Joined: Wed May 22, 2019 11:39 am

Get Current Date

Post by Robb » Mon Oct 17, 2022 12:21 pm

Hiya,

Any help would be greatly appreciated!!

I would like to get the current date, so I can then pass this into a 'Validation' step (as a variable) to confirm the date displayed on a web page is the current date.

I have seen some other posts which suggest I need to use the following code:

Code: Select all

 string systime  = System.DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss"); 
However, I'm not sure where or how I'm using this code.
Can someone kindly advise if I need to add a 'User Code' step to my existing Recording module, give any 'Method' name, and for the 'Arguments' I change 'Type' to 'String' and paste the above code?

I apologise for perhaps a rather basic question, I'm clearly not a developer!!! :D

Many thanks,

Rob

IvanF
Posts: 151
Joined: Thu Aug 11, 2022 8:55 pm

Re: Get Current Date

Post by IvanF » Mon Oct 17, 2022 5:01 pm

Hi, you could first add the collection for your code snippets as described here - https://www.ranorex.com/help/latest/ran ... d-methods/

Then define the method to look something like this (may not be the most optimal, but it works)
CurrentDateCodeSnippet.png
Lastly, add the step for the module using these instructions - https://www.ranorex.com/help/latest/ran ... e-library/

You can run these 3 lines to make sure the method works
DateActionTable.png
You do not have the required permissions to view the files attached to this post.

Robb
Posts: 6
Joined: Wed May 22, 2019 11:39 am

Re: Get Current Date

Post by Robb » Tue Oct 18, 2022 10:53 am

Thank you.

This worked, and I learnt something new

Many thanks for the help!!