Seperating hours and minutes from the 00:00 format

So I have a string variable that contains the amount of time that something took in the HH:MM format
I would like to seperate the hours and minutes into 2 seperate strings.
output: str1 = HH ; str2 = MM

How would I go about doing that?

Date.ParseExact(“11:22”,“hh:mm”,System.Globalization.CultureInfo.InvariantCulture).Hour.ToString

Date.ParseExact(“11:22”,“hh:mm”,System.Globalization.CultureInfo.InvariantCulture).Minute.ToString

1 Like

You also can

  • spit string by “:” chracter
  • use regex
1 Like

Hi,

Hope the following expressions helps you.

str1 = yourString.Split(":"c)(0)
str2 = yourString.Split(":"c)(1)

If your string contains except “HH:MM”, you need to extract “HH:MM” in advance as the following.

yourString = System.Text.RegularExpressions.Regex.Match(yourString,"\d{1,2}:\d{1,2}").Value

THen

str1 = yourString.Split(":"c)(0)
str2 = yourString.Split(":"c)(1)

Regards,

1 Like