473,396 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Convert.ToDateTime ERROR

I am running an ASP.net program written in VB. At one point I try to convert
a date string into a date time object... this string is from a central dev
server and the code works on many other machines.

Convert.ToDateTime("")

I get the string in the format MM/DD/YYYY (06/26/2007)

The code breaks and I get the "String was not recognized as a valid
DateTime" error message unless I manually change the input string to
DD/MM/YYY (26/06/2007).

I went into control panel "Regional Settings" and changed from Canadian to
US... where short date is MM/DD/YYYY... that didn't seem to help.

Does anyone know how I can fix this rather annoying issue?
Dec 10 '07 #1
4 2970
"andrew" <an****@discussions.microsoft.comschrieb
I am running an ASP.net program written in VB. At one point I try
to convert a date string into a date time object... this string is
from a central dev server and the code works on many other machines.

Convert.ToDateTime("")

I get the string in the format MM/DD/YYYY (06/26/2007)

The code breaks and I get the "String was not recognized as a valid
DateTime" error message unless I manually change the input string to
DD/MM/YYY (26/06/2007).

I went into control panel "Regional Settings" and changed from
Canadian to US... where short date is MM/DD/YYYY... that didn't seem
to help.

Does anyone know how I can fix this rather annoying issue?
Dim d As Date = Date.ParseExact("06/26/2007", "MM\/dd\/yyyy", Nothing)
Armin
Dec 10 '07 #2
I'm working in a group of maybe 50 developers... and the code works on all of
their machines... in fact before my machine was re-ghosted it also worked on
mine. I don't think changing the code is an option for me.

"Armin Zingler" wrote:
"andrew" <an****@discussions.microsoft.comschrieb
I am running an ASP.net program written in VB. At one point I try
to convert a date string into a date time object... this string is
from a central dev server and the code works on many other machines.

Convert.ToDateTime("")

I get the string in the format MM/DD/YYYY (06/26/2007)

The code breaks and I get the "String was not recognized as a valid
DateTime" error message unless I manually change the input string to
DD/MM/YYY (26/06/2007).

I went into control panel "Regional Settings" and changed from
Canadian to US... where short date is MM/DD/YYYY... that didn't seem
to help.

Does anyone know how I can fix this rather annoying issue?

Dim d As Date = Date.ParseExact("06/26/2007", "MM\/dd\/yyyy", Nothing)
Armin
Dec 10 '07 #3
"andrew" <an****@discussions.microsoft.comschrieb
I'm working in a group of maybe 50 developers... and the code works
on all of their machines... in fact before my machine was re-ghosted
it also worked on mine. I don't think changing the code is an
option for me.

"Armin Zingler" wrote:
"andrew" <an****@discussions.microsoft.comschrieb
I am running an ASP.net program written in VB. At one point I
try to convert a date string into a date time object... this
string is from a central dev server and the code works on many
other machines.
>
Convert.ToDateTime("")
>
I get the string in the format MM/DD/YYYY (06/26/2007)
>
The code breaks and I get the "String was not recognized as a
valid DateTime" error message unless I manually change the input
string to DD/MM/YYY (26/06/2007).
>
I went into control panel "Regional Settings" and changed from
Canadian to US... where short date is MM/DD/YYYY... that didn't
seem to help.
>
Does anyone know how I can fix this rather annoying issue?
Dim d As Date = Date.ParseExact("06/26/2007", "MM\/dd\/yyyy",
Nothing)

Convert.todatetime uses the current culture. The string to be parsed is not
guaranteed to be in the current culture's datetime format. That's why the
code is not correct and should be changed.

I don't know why it still doesn't work after changing the regional settings.
Have you also tried it in a new test application on the same machine in a
user account?
Armin

Dec 10 '07 #4
I managed to work around it by changing my culture in my machine.config file.

"Armin Zingler" wrote:
"andrew" <an****@discussions.microsoft.comschrieb
I'm working in a group of maybe 50 developers... and the code works
on all of their machines... in fact before my machine was re-ghosted
it also worked on mine. I don't think changing the code is an
option for me.

"Armin Zingler" wrote:
"andrew" <an****@discussions.microsoft.comschrieb
I am running an ASP.net program written in VB. At one point I
try to convert a date string into a date time object... this
string is from a central dev server and the code works on many
other machines.

Convert.ToDateTime("")

I get the string in the format MM/DD/YYYY (06/26/2007)

The code breaks and I get the "String was not recognized as a
valid DateTime" error message unless I manually change the input
string to DD/MM/YYY (26/06/2007).

I went into control panel "Regional Settings" and changed from
Canadian to US... where short date is MM/DD/YYYY... that didn't
seem to help.

Does anyone know how I can fix this rather annoying issue?
>
Dim d As Date = Date.ParseExact("06/26/2007", "MM\/dd\/yyyy",
Nothing)


Convert.todatetime uses the current culture. The string to be parsed is not
guaranteed to be in the current culture's datetime format. That's why the
code is not correct and should be changed.

I don't know why it still doesn't work after changing the regional settings.
Have you also tried it in a new test application on the same machine in a
user account?
Armin

Dec 10 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Franck | last post by:
Hi, 'm gettin mad about date conversion. Here is the point. Got and add-in for Excel which call functions from a web service (on a remote server) The remote server has regional settings...
5
by: simon | last post by:
I have datetime variable: Datetime tsEndTime; Should I use (DateTime): tsEndTime=(DateTime)rdr.GetValue(15) or is better to use: tsEndTime=Convert.ToDateTime(rdr.GetValue(15))
19
by: simon | last post by:
I get from the dateTimePicker the value: string="12/18/2003 11:52:28 AM" Now I need to convert this to dateTime. Any function I use: Convert.ToDateTime(string) or Cdate(string), I get an error...
3
by: sparkle | last post by:
Hi, Does anybody know how to convert date to ticks from a dateTimePicker? What I'm using now isn't working. I'm trying to use a dateTimePicker to set an appointment in Outlook with a...
2
by: SimonZ | last post by:
Hi, can someone explain me, when to use: (DateTime)DataBinder.Eval(Container.DataItem, "dateField") OR Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "dateField")) Sometimes...
5
by: rsanan | last post by:
How do I convert a datetime from en-GB to en-US format here is my code - (not working for the clients outside of US) /*******************CODE*****************/ System.Globalization.CultureInfo...
14
by: Me | last post by:
Hi all I am getting a really bizzare error on when I convert a string into a datetime: The code is : DateTime dt1 = Convert.ToDateTime("10 Sep 2005"); Console.WriteLine(dt1.Year);
4
by: tshad | last post by:
Is there any difference between convert.ToDateTime and System.DateTime.Parse? I am using them both and they seem the same. Is one better to use than another? Thanks, Tom
1
by: John | last post by:
I have a drop down that is showing dates, I need to pass the selected date to my proc, so I pass it like this; ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.