String to DateTime Problem

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.
 
A

Armin Zingler

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top