Convert string to datetime

Hello, just curious because I already have workaround to accomplish my needs.

I use

$todaydate = (get-date).ToString('yyyyMMddhhmmss')
$newfile = "D:\SCRIPTS\PS1\Testing\CSV\$todaydate.csv"

to generate a name for my CSV.

The name of CSV is like 20150312023054.csv

How to revert "20150312023054"  back to DateTime object?

$a = "20150312023054"
$date =  ...  ???

March 24th, 2015 4:47am

You can use ParseExact - 

[datetime]::parseexact("20150312023054", 'yyyyMMddHHmmss', [System.Globalization.CultureInfo]::DefaultThreadCurrentCulture)

  • Marked as answer by Mekac 21 hours 46 minutes ago
Free Windows Admin Tool Kit Click here and download it now
March 24th, 2015 5:08am

You can use ParseExact - 

[datetime]::parseexact("20150312023054", 'yyyyMMddHHmmss', [System.Globalization.CultureInfo]::DefaultThreadCurrentCulture)


Thanks :)
March 24th, 2015 5:22am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics