Last active
May 26, 2020 11:23
-
-
Save Ellestad1995/c4ec8fd86ed54a7883373517cb352c6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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