Search code examples
c#stringc#-4.0format

To retrieve Year, Month and Day


How to retrieve year, month and day from the file name like MONTUE-API-202310031200340313.TXT

Below is the pattern which will not changed

MONTUE-API-{YEAR}{MONTH}{DAY}{TIMESTAMP}.TXT

I want to get {YEAR}{MONTH}{DAY} from this file name

MONTUE-API-202310031200340313.TXT

I am trying to get the output as 20231003.

Thank you


Solution

  • I have used substring as commented by Johnathan Barclay in the question to achieve my desired result

    var output = input.Substring(11, 8);