Ask a Question

Trying to get a current date to enter into a field

Occasional Contributor

Trying to get a current date to enter into a field

Here is the originally generated vb script:

Call SSCalendarMaskedEdit.Keys("03152011[Tab]")

And we are attempting to place a current date into the field minus a set number of days and all of our current attempts to seems to cause errors and I'm unsure what were putting in wrong. To clarify Current Date Minus say 15 days (Ex. 10/30/2011 - 15 days = 10/15/2011)

Here is one of our recent attempts: Giving the error - Object required: 'DateValue(...)'

Dim dtmTest

Dim formatedDate

Dim currentDate

Set currentDate = DateValue(Now)

Set dtmTest = DateAdd("D", -15, currentDate)

Set formatedDate = Format(dtmTest, "mmddyyyy")

Call SSCalendarMaskedEdit.Keys(formatedDate & "[Tab]")

The way we have achieved this in the past using a slightly different method was such:

(Format(DateAdd("D", -15, Now), "mmddyyyy") )

This would not work either.

Can anyone assist me with the proper terms that will work within TestComplete?

Also, the return for 3/1/2011 would need to be formatted like: 03012011

Thanks for the help
Esteemed Contributor

You'll want to use a combination of aqDateTime and aqConvert objects.  So, the following function will write to the log today's date minus 5 days...

function tada()


    var TodaysDate = aqDateTime.Now()

    var FiveDaysAgo = aqDateTime.AddDays(TodaysDate, -5)

    var FormattedDate = aqConvert.DateTimeToFormatStr(FiveDaysAgo, "%m%d%Y")



You'll need to adapt it for VBScript but this should demonstrate how to use those two object.

Relevant documentation: - aqDateTime.Now - aqDateTime.AddDays - aqConvert.DateTimeToFormatStr

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Occasional Contributor

Thanks for the help, I had stumbled upon the articles you mentioned just prior to you posting this.

This is the result that we got working:

Call SSCalendarMaskedEdit.Keys(aqConvert.DateTimeToFormatStr(aqDateTime.AddDays(aqDateTime.Now , -15), "%m%d%Y") & "[Tab]")

Thanks again.
SmartBear Alumni (Retired)

Hi Jason,

While you've already got a working answer, I'd still like to explain the "Object required: 'DateValue(...)" error you got with your original code. It's caused by improper use of the Set keyword. In VBScript, you use Set only for object assignments. When a variable is assigned a simple value -- a string, number, date, etc. -- Set isn't needed:

currentDate = DateValue(Now)

dtmTest = DateAdd("D", -15, currentDate)

Helen Kosova
SmartBear Documentation Team Lead
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Occasional Contributor

Thanks for the assist, writing code isn't my primary background so sometimes I feel like I'm using a chainsaw for surgery but I'm learning and I read these forums quiet a bit for tips and tricks to pick up.
Showing results for 
Search instead for 
Did you mean: