Skip to content

Instantly share code, notes, and snippets.

@Ellestad1995
Last active May 26, 2020 11:23
Show Gist options
  • Save Ellestad1995/c4ec8fd86ed54a7883373517cb352c6b to your computer and use it in GitHub Desktop.
Save Ellestad1995/c4ec8fd86ed54a7883373517cb352c6b to your computer and use it in GitHub Desktop.
# 05.06.2020 00:00:00
$format = "dd.MM.yyyy hh:mm:ss";
function IsDateTime($date)
{
try{
if($date.GetType().Name -eq 'String'){
[datetime]$dirDate = New-Object DateTime
if (!([DateTime]::TryParseExact($date,$format, [System.Globalization.CultureInfo]::InvariantCulture, [System.Globalization.DateTimeStyles]::None, [ref]$dirDate)))
{
return $false
}
return $true
}elseif($date.GetType().Name -eq 'DateTime'){
return $true
}else{
throw 'Unknown type'
}
}catch{
throw 'Empty date'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment