String to DateTime Problem

  • Thread starter Thread starter Lee
  • Start date Start date
L

Lee

Hello all,

I'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.
 
Lee said:
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.


I'd try:

myDateTime = DateTime.ParseExact("MM/dd/yyyy HH:mm:ss')


see also:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcustomdatetimeformatstrings.asp


Armin
 
Back
Top