Get month and year from date and time

I just want to extract month and year from this string “2019-03-16T09:53:37.000Z”. Is there any solution for that. Thanks in advance.

@Emma1,

Try Below one:

str = “2019-03-16T09:53:37.000Z”
Year: str.Split("-".ToCharArray)(0)
Month: str.Split("-".ToCharArray)(1)

1 Like

DateTime dt=date.ParseExact("2019-03-16T09:53:37.000Z","yyyy-MM-dd'T'HH:mm:ss.fff'Z'", system.Globalization.DateTimeFormatInfo.InvariantInfo)

intMonth=dt.Month
intYear=dt.Year

Regards,
Arivu :slight_smile:

1 Like

@lakshman thank you so much it worked.

1 Like

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