(aqDateTime["Today"](), "%Y%m%d") -1); problem
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
(aqDateTime["Today"](), "%Y%m%d") -1); problem
TesComplete 14.01 version:
Code:
var DateYesterday = (aqConvert["DateTimeToFormatStr"](aqDateTime["Today"](), "%Y%m%d") -1);
Log["Message"]("Date inputed: " + (aqConvert["DateTimeToFormatStr"](aqDateTime["Today"](), "%Y%m%d") -1));
Output:
Date inputed: 20211200
Region and Language are set to Ukraine.
Anyone knows how to deal with this problem in the future ?
Solved! Go to Solution.
- Labels:
-
Desktop Testing
-
Script Tests
-
Test Results
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
What is the end goal here? Maybe there is a easier pre-built method.
Best,
Matt
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @DainiusA -
It looks to me like you are trying to get yesterdays date - please see a function here:
https://support.smartbear.com/testcomplete/docs/scripting/working-with/dates/cscript.html#Tomorrow
function YesterdayDate()
{
// Obtain the current date
var CurrentDate = aqDateTime.Today();
// Convert the date/time value to a string and post it to the log
Today = aqConvert["DateTimeToStr"](CurrentDate);
Log["Message"]("Today is " + Today);
// Calculate the yesterday’s date, convert the returned date to a string and post this string to the log
YesterdayDate = aqDateTime["AddDays"](CurrentDate, -1);
ConvertedYesterdayDate = aqConvert["DateTimeToStr"](YesterdayDate);
Log["Message"]("Yesterday was " + ConvertedYesterdayDate);
}
Let me know if this is not what you are trying to do or if you have questions.
Emma
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, Matt,
The end goal is that I have a keyboard form in which
ineed to press the numbers accordingly the yesterday date and today date:
From:
To:
The full script that I wrote for it to work:
//USEUNIT KeypadNumbers
function SeniorCashierCoordinatesDateClick()
{
var DateYesterday = (aqConvert["DateTimeToFormatStr"](aqDateTime["Today"](), "%Y%m%d") -1);
var DateToday = (aqConvert["DateTimeToFormatStr"](aqDateTime["Today"](), "%Y%m%d"));
Log["Message"]("Date inputed: " + (aqConvert["DateTimeToFormatStr"](aqDateTime["Today"](), "%Y%m%d") -1));
for (var i = 0; i < aqString["GetLength"](DateYesterday); i++)
{
PressNumber( aqString["GetChar"](DateYesterday, i));
}
ClickOk()
Log["Message"]("Date inputed: " + aqConvert["DateTimeToFormatStr"](aqDateTime["Today"](), "%Y%m%d") )
for (var i = 0; i < aqString["GetLength"](DateToday); i++)
{
PressNumber( aqString["GetChar"](DateToday, i));
}
ClickOk()
}
It works for me perfectly on any other day. But I have an issue then it comes to the first day of the month
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok this one works until i try to change the format of the date
YesterdayDate = aqDateTime["AddDays"](CurrentDate,"%Y%m%d" -1);
I get an error Overflow on this one. Maybe I am doing it in some kind of wrong order ?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @DainiusA -
I believe this is the code you are looking for : Log["Message"](aqConvert["DateTimeToFormatStr"](YesterdayDate, "%Y%m%d"));
Let me know if this helps.
Emma
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not quite. In the Log it shows the format the one I need: But the thing is I need to press buttons one by one in this order on my keypad
Sample code without date formatting that works at this moment:
function YeterdayInput ()
{
var CurrentDate = aqDateTime.Today();
// Convert the date/time value to a string and post it to the log
Today = aqConvert["DateTimeToStr"](CurrentDate);
// Calculate the yesterday’s date, convert the returned date to a string and post this string to the log
DateYesterday = aqDateTime["AddDays"](CurrentDate, -1);
ConvertedYesterdayDate = aqConvert["DateTimeToStr"](DateYesterday);
for (var i = 0; i < aqString["GetLength"](DateYesterday); i++)
{
PressNumber( aqString["GetChar"](DateYesterday, i));
}
ClickOk()
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey @DainiusA!
Good news here is that aqDateTime also has a AddDays function that will allow you to add or remove a specific amount of days that will adhere to the calendar.
For instance, in the code below we create variables that hold Todays date, then we subtract one from it. The AddDays function will roll the time back to the previous month if Todays date is the first of the month.
// script start
function yesterDay()
var today, yesterdayRaw, yesterdayFormatted;
today = aqDateTime.Today();
yesterdayRaw = aqDateTime.AddDays(today, -1);
yesterdayFormatted = aqConvert.DateTimeToFormatStr(yesterdayRaw, "%Y%m%d");
Log["Message"]("yesterdayFormatted " + (yesterdayFormatted));
// script end
Here are some docs that cover these functions. I hope this helps!
https://support.smartbear.com/testcomplete/docs/scripting/working-with/dates/javascript.html
https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/adddays.html
Regards,
Nick
Solutions Engineer @ SmartBear
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
