Extract digits from string and convert to Date

Hey! So I need to extract the first 8 digits from the string (screenshot attached). And once I extract the digits, which in this case are: 20190705 (YearMonthDay) , convert it to date format 7/05/19 (Month/Day/Year). I know it’s a bit complicated but I would appreciate help.

Capture

Thanks !

are you already able to get that string: 20190705 into a variable? If yes, then do:
Date.ParseExact("20190705", "yyyyMMdd", System.GlobalizationCultureInfo.InvariantCulture).ToString("M/dd/yy")

Hi @bcorrea,

Thank you so much! And no I still can’t get it into variable, I tried several things…

You can use regex like this:
(?<=Pay Period(s): )(.*)(?= )

Hi, can you please tell me what variable type I need to use for this “Date.ParseExact(“20190705”, “yyyyMMdd”, System.GlobalizationCultureInfo.InvariantCulture).ToString(“M/dd/yy”)” ?
Because I tried DateTime but it’s not the one.

Thanks!

StringVariable = Date.ParseExact("20190705", "yyyyMMdd", System.GlobalizationCultureInfo.InvariantCulture).ToString("M/dd/yy")

It says that GlobalizationCulturInfo is not part of System

System.Globalization.CultureInfo

Oh Thank you!

1 Like

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