-1

YYYYMMDD in files that are entered inconsistently for example 10-24-2007, Oct-24-07, oct-07

  • 2
    Your question lacks detail. Put an example of file content and an example of the output you want to see. What have you tried? – Bill_Stewart Apr 11 '18 at 17:36
  • What would you expect `Oct-07` to be converted to? 1st or 31st of October 2007? are the files' basenames just dates, or do they have other characters in them? – Mathias R. Jessen Apr 11 '18 at 17:39

1 Answers1

1

Data quality issues aside, the basic operation is easy: cast the string into a [datetime] object:

PS[1] (85) > [datetime] "Oct-07"
Sunday, October 7, 2018 12:00:00 AM

PS[1] (86) > [datetime] "10-24-2007"
Wednesday, October 24, 2007 12:00:00 AM

PS[1] (87) > [datetime] "Oct-24-07"
Wednesday, October 24, 2007 12:00:00 AM

Then format that object however you want:

PS[1] (92) > ([datetime] "Oct-24-07").tostring("yyyy-MM-dd")
2007-10-24
Bruce Payette
  • 2,511
  • 10
  • 8