New Member.

Change Date Format using DotNetFactory


I know that UFT does not have any built-in function to simply change date format to the desired format unlike VBA function Format(Expression,Format) hence I'm using DotNetFactory to do it.

I had some luck running it for first couple of times but now I'm running into following error. I would appreciate if anyone could help.

Run Error - Step
External object System.DateTime::Parse has thrown the following exception:
Object reference not set to an instance of an object.
GenralTasks.qfl!DateManipulate Line 255: "Set oDate = MyDate.Parse(sDate)"


Function DateManipulate(sDate)
Set MyDate = DotNetFactory.CreateInstance("System.DateTime")
Set oDate = MyDate.Parse(sDate)
DateManipulate = oDate.ToString("yyyy-MM-dd")
Set MyDate = Nothing
End Function


Mohd Akhtar

Labels (1)
1 Reply
New Member.

Re: Change Date Format using DotNetFactory

I did some more debugging with the code and found that UFT is storing sDate in Datatype = Date which is not recognized by the.parse parameter as it is looking for a String Data type. 

Any work around that?

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.