Identify the latest time from two strings

Hello Team,

I had two strings like :
strStart="AR_Invoice 20112023102553
strEnd="AR_Invoice 20112023102554

in the above 2 strings the format is like, AR_Invoice (DateFormat)(TimeFormat)
i have to identify which is the latest one based on the time format.

any responses are appreciated.

Thanks,
Shiva

Hi @shivarajvp555 ,

Could you maybe check with the below Expression :

DateTime.ParseExact(Regex.Match(strVar1,"(?<=AR_Invoice\s+).*").Value.Trim,"ddMMyyyyhhmmss",System.Globalization.CultureInfo.InvariantCulture)>DateTime.ParseExact(Regex.Match(strVar2,"(?<=AR_Invoice\s+).*").Value.Trim,"ddMMyyyyhhmmss",System.Globalization.CultureInfo.InvariantCulture)

image

If the Above Expression results in false, it would mean the str2 is greater/latest

Hi @shivarajvp555

dateTimeStart = DateTime.ParseExact(strStartDateTime, “yyyyMMddHHmmss”, System.Globalization.CultureInfo.InvariantCulture)
dateTimeEnd = DateTime.ParseExact(strEndDateTime, “yyyyMMddHHmmss”, System.Globalization.CultureInfo.InvariantCulture)

Use IF activity

If dateTimeStart > dateTimeEnd
Then
latestDateTime = dateTimeStart
Else
latestDateTime = dateTimeEnd

Hi @shivarajvp555

Try this:

strStart = "AR_Invoice 20112023102553"
strEnd = "AR_Invoice 20112023102554"

timeFormatStart = DateTime.ParseExact(strStart.Substring(strStart.Length - 12), "HHmmss", System.Globalization.CultureInfo.InvariantCulture)
timeFormatEnd = DateTime.ParseExact(strEnd.Substring(strEnd.Length - 12), "HHmmss", System.Globalization.CultureInfo.InvariantCulture)

If timeFormatStart > timeFormatEnd Then
    result = "strStart is the latest."
ElseIf timeFormatStart < timeFormatEnd Then
    result = "strEnd is the latest."
Else
    result = "Both have the same time."
End If

LogMessage(result)

timeFormatStart and timeFormatEnd are of Datatype System.DateTime

Hope it helps!!

Hi @supermanPunch

Can you please help me to understand what is this logic you built Please.

Thanks @sanjay3 .
This solution also worked.

@shivarajvp555 ,

The Expression could be broken down into two parts :

Date Value Extraction Expression :

Regex.Match(strVar1,"(?<=AR_Invoice\s+).*").Value.Trim)

Conversion of String Date to Date Time type (For Comparison) :

DateTime.ParseExact(`Output From Regex Matche`,"ddMMyyyyhhmmss",System.Globalization.CultureInfo.InvariantCulture)