Leading zeros are not dropped when using %#d in aqConvert.DateTimeToFormatStr function
I need to remove leading zeros from the day when using date formats e.g. 7/15/1994 instead of 07/15/1994 however when I use the aqConvert.DateTimeToFormatStr function it does not drop the leading zero even though the TestComplete documentation mentions if using the # flag in the format specifier, the leading zeros are removed from the number. (https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/date-and-time-format-specifiers.html?sbsearch=leading%20zeros)
Here is the code I used (Python):
DOBField = "DOB - DOD:\n{} - {}".format(aqConvert.DateTimeToFormatStr(Driver.value[3], "%m/%#d/%Y"), aqConvert.DateTimeToFormatStr(Driver.value[6], "%m/%#d/%Y"));
Log.Message(DOBField);
The Driver.value[3] and Driver.value[6] is the data that is retrieved from an Excel spreadsheet. The date in these two fields correspond to 7/15/1994 and 6/17/2017.
When I run the script, it logs the following "DOB - DOD:07/15/1994 - 06/17/2017"
I expected to get "DOB - DOD:7/15/1994 - 6/17/2017"
If I remove the # from the %#d format specifier, it still returns the date with the leading zeros. Can anyone advise what I am doing wrong in my code? Thanks.
Hi sedens!
Pardon any confusion here on my part, but it appears you are looking to drop the zero from the Month in this case? Which means we need to apply the '#' to the Month section as well, instead of just the Day.
This formatting removes all the zeros from your date in a script I built out;
aqConvert.DateTimeToFormatStr(myDate, "%#m/%#d/%Y")
I hope this helps!