Home All Groups Group Topic Archive Search About

String to DateTime Problem

Author
2 Jul 2005 6:15 PM
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.


--
Warm Regards,

Lee

Author
2 Jul 2005 7:31 PM
Armin Zingler
Show quote Hide quote
"Lee" <luv2program2***@yahoo.com> schrieb
> 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
Author
2 Jul 2005 8:08 PM
Lee
Armin Zingler enlightened me by writing:


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

That works better, Armin.  Thank you. Looks like I need to study the
formatting templates in .net a bit more.


--
Warm Regards,

Lee