Unable to convert a string to an integer variable from DateTaken attribute on a JPG file

A better approach to working with dates is to convert the date string to an actual DateTime object, which provides all the information you’re looking for:

$culture = [Globalization.CultureInfo]::InvariantCulture
$pattern = 'dd\/MM\/yyyy'

$datestring = $objFolder.GetDetailsOf($File, 12).Split(' ')[0]
$datetaken  = [DateTime]::ParseExact($datestring, $pattern, $culture)

$year      = $datetaken.Year
$month     = $datetaken.Month              # month (numeric)
$monthname = $datetaken.ToString('MMMM')   # month name

Assuming that the date is followed by a time in the format HH:mm:ss you could extend the code to handle the time as well:

$culture = [Globalization.CultureInfo]::InvariantCulture
$pattern = 'dd\/MM\/yyyy HH:mm:ss'

$datestring = $objFolder.GetDetailsOf($File, 12)
$timestamp  = [DateTime]::ParseExact($datestring, $pattern, $culture)

$year      = $timestamp.Year
$month     = $timestamp.Month              # month (numeric)
$monthname = $timestamp.ToString('MMMM')   # month name
$hour      = $timestamp.Hour
...

Leave a Comment