asp.net - String to Date conversion -


hi receiving error of string date conversion here's script

 protected sub btnsave_click(sender object, e eventargs) handles btnsave.click  dim oval new collections 'time stamp oval.add(datetime.parseexact(request.cookies("timestarted").value.tostring, "dd-mm-yyyy hh:mm:ss", nothing), "ofield_starttime") oval.add(dt.tostring("dd-mm-yyyy hh:mm:ss"), "ofield_stoptime") savetime(oval) 

and under public function savetime(oval collection)

dim squery new sqlcommand squery.commandtype = commandtype.storedprocedure squery.commandtext = "psc_timestamp"  squery.parameters     .addwithvalue("@pscstart", convert.todatetime(oval("ofield_starttime")))     .addwithvalue("@pscstop", cdate(oval("ofield_stoptime")))  end squery.connection = myconnection if myconnection.state = 1 'check if connection open     myconnection.close() end if myconnection.open() squery.executenonquery() myconnection.close() 

i receiving error

conversion string "13-07-2015 13:09:38" type 'date' not valid.

a helping hand highly appreciated...thanks in advance.

the problem don't specify error happening. if it's following line:

datetime.parseexact(request.cookies("timestarted").value.tostring, "dd-mm-yyyy hh:mm:ss", nothing) 

... find interesting passing nothing final iformatprovider provider parameter. when that, defaults current culture. possible current culture messing how data being parsed?

to ensure consistent behavior, try passing cultureinfo.invariantculture instead:

datetime.parseexact(request.cookies("timestarted").value.tostring, "dd-mm-yyyy hh:mm:ss", cultureinfo.invariantculture) 

if error happening following lines:

.addwithvalue("@pscstart", convert.todatetime(oval("ofield_starttime"))) .addwithvalue("@pscstop", cdate(oval("ofield_stoptime"))) 

then, make sure change date conversion logic use datetime.parseexact , should fine.


Comments