Extract Year from a date

Hi, I have an input date in format “Jan 25” where Jan is month and 25 is year. But the day is not specified in the input date. How can I extract only year 2025 from this input? I tried with code Convert.ToDateTime(inputDate).Year which returns 2023 as output. But I want 2025 as output. Can anyone please suggest a solution for this issue? Thanks in advance!

Kind Regards,
Renju

@renjutom

Please try this

Datetime.ParseExact("Jan 25","MMM yy",System.Globalization.CultureInfo.InvariantCulture).Year

cheers

1 Like

Hi @renjutom ,

Can you try this

inputDate=“Jan 25”

Datetime.ParseExact(inputDate,"MMM yy",System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy")

Thanks!

1 Like

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