How can I extract dates from a funky filename (date's in name as yyyyMMdd)
here's example, but, last line doesn't convert [datetime].
$pattern = "(?<text>.*)(?<date>\d{8})(?<text2>.*)" "a_12345678_at.txt" -match $pattern | out-null ([datetime] ($matches.date)).tostring('mm-dd-yyyy') throws error:
cannot convert value "20120224" type "system.datetime". error: "string not recognized valid datetime." @ line:1 char:23 + ([datetime] ($matches. <<<< date)).tostring('mm-dd-yyyy') + categoryinfo : notspecified: (:) [], runtimeexception + fullyqualifiederrorid : runtimeexception see mjolinor, using regexes... :) i threw in group names.
ps > [datetime]::parseexact("20120224","yyyymmdd",$null).tostring('mm-dd-yyyy') 02-24-2012
Windows Server > Windows PowerShell
Comments
Post a Comment