DCat1223
3 years agoFrequent Contributor
Formatting a date in a Code Snippet
Hello. I have a test script where I need to input the week beginning date in a date field. The format of the date field is mmddyyyy. I am using this code snippet: (Date-WEEKDAY(Date())+1) The is...
- 3 years ago
Hey DCat1223!
We have a 'DateTimeToFormatString' method we can call on date objects that allows you to specify specific formatting.
In the example below I am using the 'aqDateTime.Today()' method to get the current date, then using the 'aqConvert.DateTimeToFormatStr' to format the dates how you have requested above.
Sub DateTimeToFormatStrSample Dim date date = aqDateTime.Today() Log.Message("Unformatted raw date from aqDateTime " & aqDateTime.Today) Log.Message("Formatted Date = " & aqConvert.DateTimeToFormatStr(date, "%m%d%Y")) End Sub
Here you can see the unformatted and formatted output that handles the 'MMDDYYYY' requirement.
Here are links to the documentation used for this solution;
'aqDateTime.Today Method'
https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/today.html
'aqConvert.DateTimeToFormatStr Method'
I hope this helps!