Update your date script code as below:
#Add leading zero into the day and month to avoid error in ParseExact
if($row.CreatedDate.Trim() -ne "")
{
$oldDate = $row.CreatedDate.Trim().Replace('/','-')
$newDate = $oldDate.Split("-")[0].ToString().PadLeft(2, '0')+'-'+$oldDate.Split("-")[1].ToString().PadLeft(2, '0')+'-'+$oldDate.Split("-")[2].ToString().PadLeft(2, '0')
$csvDate = [DateTime]::ParseExact($newDate,"dd-MM-yyyy",[CultureInfo]::InvariantCulture)
$item["PublishDate"] = [Sitecore.DateUtil]::ToIsoDate($csvDate)
}
In the CSV file if the Date Column field values will be separated with -
then if would word fine. If the date column field value will be separated with /
then the code will return a null error. So in the above code, I have trimmed the CreatedDate
field and replace the '/' with '-' and do remember to add leading zero into the day, month to avoid error in ParseExact
.