How to identify the year in Q1'21 as 2021?

Hi Team

I have a data like Q1’21 in an excel. I have to compare if it is current year i.e 2021. How to put the logic so that bot will know Q1’21 year is 2021 ?

give a try on detecting year with a regex
Simple One:
grafik

more specific:
grafik

@kkpatel

You can use contains method of string.

suppose, you have string variable str that have value Q1’21,

if str.contains(21) {
do u wanna
}

or go with @ppr’s way.

Cheers,
Pankaj

@kkpatel,

Import System.Globalization namespace and then try the below code.

CultureInfo.CurrentCulture.Calendar.ToFourDigitYear(Int32.Parse("Q1'21".Substring(3))).ToString

Thanks @sarathi125
Its giving the result as 2021.

Hi @sarathi125

Similarly can we also do for Jan’21. How can we identify if this is first month ?

@kkpatel,

Try this, it will work for both values Q1’21 and Jan’21

CultureInfo.CurrentCulture.Calendar.ToFourDigitYear(Int32.Parse("Jan'21".Split("'"c)(1))).ToString

No I was asking for month not year. It should identify Jan means first month. Like it outputs Now.Month.

But as of now I am handling it through If condition.

@kkpatel

Try with the following code, but always the Month name you are passing should have 3 letters.

DateTime.ParseExact("Aug'21".Split("'"c)(0), "MMM", CultureInfo.CurrentCulture ).Month.ToString

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