Regexexpressiondatetime

I have a str = “wed02.03.23 : 12:00pm-02:00pm”

I need to the output

Strdate =02.03.23
StrStratTime=12:00pm
StrEndtime = 02:00pm

HI @Arya_Squares

Checkout this expressions

StartDAte

System.Text.RegularExpressions.Regex.Match(InputString,"\d{2}\.\d{2}\.\d{2}").Tostring

StartTime

System.Text.RegularExpressions.Regex.Match(InputString,"\d{2}\:\d{2}\w+(?=\-)").Tostring

EndTime

System.Text.RegularExpressions.Regex.Match(InputString,"\d{2}\:\d{2}\w+$").Tostring

Regards
Sudharsan

Hi,

FYI, another pattern:

Strdate = System.Text.RegularExpressions.Regex.Match(yourString,"[.\d]+(?=\s*:)").Value

StrStratTime = System.Text.RegularExpressions.Regex.Match(yourString,"\S+(?=-)").Value

StrEndtime = System.Text.RegularExpressions.Regex.Match(yourString,"(?<=-)\S+").Value

Sample20230301-1aL.zip (2.2 KB)

Regards,

1 Like

HI @Arya_Squares

How about this regex expression

Strdate = System.Text.RegularExpressions.Regex.Match(yourString,"\d{2}.\d{2}.\d{2}").Tostring.Trim

StrStratTime = System.Text.RegularExpressions.Regex.Match(yourString,"\d{2}:\d{2}\S+(?=-)").Tostring.Trim

StrEndtime = System.Text.RegularExpressions.Regex.Match(yourString,"(?<=-)\d{2}:\d{2}\S+").Tostring.Trim

Regards
Gokul

1 Like

Hi @Arya_Squares ,

Maybe alternate using String Manipulation :

StrDate = Split(str,":")(0).Trim.SubString(3)

StrStartTime = Split(Split(str,":")(1).Trim,"-")(0).Trim

StrEndTime = Split(Split(str,":")(1).Trim,"-")(1).Trim
1 Like

Thank q soo much for ur response

It’s really helped me a lot

In the same condition

I have a secenario like this

Start time - end time the different is greater than 1hours we need to check can you please help on this

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.