Change the / in aqDateTime.Today to -
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Change the / in aqDateTime.Today to -
Hello,
For my test I need to fill in the current date. But, our system doesn't allow the current date to be with / and it needs to be - instead. Does anyone know if it is possible to change this, and if it is, how can I change it?
I added screenshots for clearance.
Thanks in advance!
Solved! Go to Solution.
- Labels:
-
Keyword Tests
-
Test Results
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
you would most likely need to create a little helper function that takes in that input date with "/" separators and replaces it with "-" instead. The syntax and the methods will differ based on the scripting language of choice, but for example, Python has the replace() method for strings, where you could switch out all "/" with "-"
Justin Kim
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
for example...
def change_date_format():
day = str(aqDateTime.GetDay(aqDateTime.Now()))
month = str(aqDateTime.GetMonth(aqDateTime.Now()))
year = str(aqDateTime.GetYear(aqDateTime.Now()))
list = [day, month, year]
seperator = "-"
inputdate = seperator.join(list)
Log.Message(inputdate)
return inputdate
and now you can drag and drop this on top of the keyword test operation where you are inputting the str value into your app, and then select the "last operation result" option instead.
Justin Kim
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To avoid string splitting and weird edge cases, it would be worth looking into aqConvert.DateTimeToFormatStr()
e.g:
function reformat_date(current_datetime) {
return aqConvert.DateTimeToFormatStr(current_datetime, "%m-%d-%Y");
}
You can find the reference for date format specifiers here.
You could do this in a script, or even just use a code snippet operation.
--------------------
Senior SQA Automation Engineer
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for the reply.
I am quite new to this, so I'm figuring things out. When I try to use your code I had to define current_datetime, and went searching in the links you provided. And tried to modify the code, but it's not working because it said that he is missing the reformat_date routine.
I did put your code in the script so the routine has to be there. One of the things that might be the problem is that you cannot nest functions? When trying to separate the two functions he says that the current_datetime isn't defined.
function DateTimeToFormatStr()
{
var current_datetime;
current_datetime = aqDateTime.Today();
function reformat_date(current_datetime) {
return aqConvert.DateTimeToFormatStr(currrent_datetime, "%m-%d-%Y");
}
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Not sure that nested functions are supported.
Consider the code like this:
function DateTimeToFormatStr()
{
var current_datetime;
current_datetime = aqDateTime.Today();
Log.Message(reformat_date(current_datetime));
}
function reformat_date(current_datetime) {
return aqConvert.DateTimeToFormatStr(currrent_datetime, "%m-%d-%Y");
}
/Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried your code out but now he says bad variable type.
Does this mean that the log message isn't the input TestComplete wants?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have no idea why it's not working for you.
Here's my code sample which works:
function reformat_date(current_datetime) {
return aqConvert.DateTimeToFormatStr(current_datetime, "%m-%d-%Y");
}
function test() {
Log.Message(reformat_date(aqDateTime.Today()));
}
Note that you might need to switch around the format string to get day and month in the correct order.
--------------------
Senior SQA Automation Engineer
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
for clarity's sake,
copy and paste the entire snippet provided by @tphillips above, and run the function called "test".
This will take the parameter of the resulting value of aqDateTime.Now() as the input value to the help function we created called "reformat_date".
So that will output, with the "-" separators that we've defined, the current date... I think the date format that you want is actually %d-%m-%Y (so change to that in your reformat_date function, for the DateTimetoFormatStr() method).
Justin Kim
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I used the snippet provided by @tphillips and running "test" the script works!
Now I'm trying to figure out how to get this value in my onscreen object. At first I thought to use the onscreen object method I can choose when running the reformat_date function.
But this results in an error.
So I tried to put the result in a string variable. And this gave no error but didn't put any data in the field.
Some time later I found a post about how to use returned results for scripts in the keyword test.
https://community.smartbear.com/t5/TestComplete-General-Discussions/how-to-use-returned-result-from-...
I tried this method by running the "test" function script and use the set variable to LastResult. This also didn't put data in the field.
Do you guys know what I am doing wrong?
