Micro Focus QTP (UFT) Forums
How to sort different dates in and get the Max date from those - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: How to sort different dates in and get the Max date from those (/Thread-How-to-sort-different-dates-in-and-get-the-Max-date-from-those)



How to sort different dates in and get the Max date from those - nilanjans - 09-05-2012

Hi all,

Have an urgent requirement.

There is webtable, where in the 6 th column we are having our dates, and those can be any dates.

date format :Thursday, September 13, 2012 (Row 1)
Saturday, September 08, 2012 (Row 2)
Friday, September 07, 2012 (Row 3)
Friday, November 23, 2012 (Row 4)

Now we need to found the max date from these dates.
say here novemmber date. Should be a generalized one.

Thanks In advance,

Nilanjan.


RE: How to sort different dates in and get the Max date from those - QTPScript - 09-07-2012

Hello

First find out row count and then start compare each month using IF condition.

Code:
if month = December then
split that month with dates and compare with each December date.
and exist...
Start with December month and start with 31 date.

You want to compare and find highest date ?. You can do using Loop. run loop and change each time value and compare the value.

It is more VB programming part.


RE: How to sort different dates in and get the Max date from those - vIns - 09-07-2012

Please use DotNetFactory object to simplify this.

Here i assume that you get the dates from the application and store it in an array
Code:
Dim arr(3)
arr(0) = "Thursday, September 13, 2012"
arr(1) = "Saturday, September 08, 2012"
arr(2) = "Friday, December 14, 2012"
arr(3) = "Friday, November 23, 2012"

This is the part sorts the date and gives you the max date in the required format

Code:
Set SystemDateTime = DotNetFactory.CreateInstance( "System.DateTime" )
Set ArrayList = DotNetFactory.CreateInstance( "System.Collections.ArrayList")
For i =0 To 3
    Set DateTime = SystemDateTime.Parse(arr(i))
    ArrayList.Add DateTime
Next
ArrayList.Sort
ArrayList.Reverse

Print "Result=" &ArrayList.item(0).GetDateTimeFormats().GetValue(7)