|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
String to DateTime ProblemI'm trying to solve a problem with a string to datetime conversion. The problem arises when I try to convert a string from an XML doc into a .net DateTime. I'm manually creating a dataset from scratch and adding the fields and their DataTypes, appending to new datatable, etc. I've googled extensively until the wee hours of the morning and just can't seem to get this to work. The format of the string is: '02/24/2005 13:00:00' I have tried several ways around it to no avail. If I use DateTime.Parse(sValue); then it truncates to just a Date. Even then the field shows as null in a DataGrid after the routine is over. If I try: myDateTime := DateTime.ParseExact('mm/dd/yyyy HH:NN:SS'); ...an exception is raised with Invalid DateTime Value. -- Warm Regards, Lee
Show quote
Hide quote
"Lee" <luv2program2***@yahoo.com> schrieb I'd try:> The format of the string is: > '02/24/2005 13:00:00' > > I have tried several ways around it to no avail. If I use > DateTime.Parse(sValue); then it truncates to just a Date. Even then > the field shows as null in a DataGrid after the routine is over. > > If I try: > > myDateTime := DateTime.ParseExact('mm/dd/yyyy HH:NN:SS'); > > ..an exception is raised with Invalid DateTime Value. myDateTime = DateTime.ParseExact("MM/dd/yyyy HH:mm:ss') see also: http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcustomdatetimeformatstrings.asp Armin Armin Zingler enlightened me by writing:
> That works better, Armin. Thank you. Looks like I need to study the> I'd try: > > myDateTime = DateTime.ParseExact("MM/dd/yyyy HH:mm:ss') > > > see also: > http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcustomdateti > meformatstrings.asp > > > Armin formatting templates in .net a bit more. -- Warm Regards, Lee
Does String mashal default to UnmanagedType.LPTStr
(newbie warning) vb.net, stdregprov, deletekey - Invalid cast Loop thru all subfolders and list all files under each use ADOX for this :-) Transparent Color in an Icon questions about VB.NET, and uses in education Is there code to convert a c# module to VB? Error: Cast From String to type Integer not valid Loading two separate instance of the same assembly score object property values against a decision rule created from from database table record values |
|||||||||||||||||||||||