string to Datetime

Hi,

I am reading values from text file and my database column type is date. not datetime

value in my text file

data[2] = 20150903 12:39:12

Exception

Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
At D:\BatchandQueries\PowerShell\Walmart\Test.PS1:128 char:45
+                         $shoppingDate = [datetime]::ParseExact <<<< ($data[2],'MM/dd/yyyy HH:mm:ss',$null)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Code:

 [DateTime]$BirthDate = Get-Date -Date "1970-01-01 00:00:00Z"
$BirthDate = [datetime]::ParseExact($data[2],'MM/dd/yyyy HH:mm:ss',$null)

How to send this string value as date to my sqlserver database column whihc has the type of date. please help me

September 6th, 2015 2:27am

[datetime]::ParseExact('20150903 12:39:12','yyyyMMdd hh:mm:ss',$null)
Free Windows Admin Tool Kit Click here and download it now
September 6th, 2015 2:44am

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

Other recent topics Other recent topics