473,785 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting String to DateTime not working

I accept a date from a user in a textbox, but I need to convert it to a DateTime.

I have the following code:

return DateTime.ParseE xact("01/10/2003", "dd/MM/yyyy", new CultureInfo("en-GB"));

When I run it on my development PC it's fine - I get 1st October 2003.

When I run it from my webserver it doesn't work - I get 10th January 2003.

I don't understand why - can anyone help?
Nov 15 '05 #1
5 8711
Cameron <co*********@ho tmail.com> wrote:
I accept a date from a user in a textbox, but I need to convert it to a DateTime.

I have the following code:

return DateTime.ParseE xact("01/10/2003", "dd/MM/yyyy", new CultureInfo("en-GB"));

When I run it on my development PC it's fine - I get 1st October 2003.

When I run it from my webserver it doesn't work - I get 10th January 2003.


How have you checked that you get 10th January 2003? Might it be that
you're then formatting it using a different culture? How are you
formatting it, in fact?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2


Thanks for the reply.

I'm just using the following to put the date back as a string:

myDate.ToString ("dd/MM/yyyy")

and the date/month are reversed from the values they entered.

Regards,
Cameron

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3
Cameron <an*******@devd ex.com> wrote:
Thanks for the reply.

I'm just using the following to put the date back as a string:

myDate.ToString ("dd/MM/yyyy")

and the date/month are reversed from the values they entered.


Hmm... that should be okay.

I can't see how that could all go wrong, to be honest. What locale is
your web server in, compared with your desktop? I can't see how it
would affect things if you're using an explicit format like the above,
but...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4


When I log onto the web server it's in the same locale as my local PC,
but usually nobody is logged into it. It just sits there with the logon
screen. Aren't locale settings stored for each user? In this case I
don't know where it takes its locale settings from when nobody is logged
on.

But I wouldn't have thought locale settings mattered when I'm telling it
the exact date formats I'm providing.

It's annoying! All my reports run for the wrong date ranges.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #5
Cameron <an*******@devd ex.com> wrote:
When I log onto the web server it's in the same locale as my local PC,
but usually nobody is logged into it. It just sits there with the logon
screen. Aren't locale settings stored for each user? In this case I
don't know where it takes its locale settings from when nobody is logged
on.

But I wouldn't have thought locale settings mattered when I'm telling it
the exact date formats I'm providing.

It's annoying! All my reports run for the wrong date ranges.


Locale settings are provided on a per user basis, but there's also a
system default. To be honest, this is a hairy topic - we've got a PC in
our office which we can't find *anything* suggesting it should be in
en_US, but it still is for some services :(

As you say, when you're specifying the exact date formats, it should be
fine though. Do you have a small sample ASP.NET page which is failing?

(As small as possible would be helpful - it could just parse and then
reformat a date which is hard-coded.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6

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

Similar topics

18
7961
by: Marcio Kleemann | last post by:
I need to force the first letter of each word in a line of text to uppercase. The text comes from a TextBox control in a Web Form. I'm new to ..NET and am having a problem. Since I can't modify the string directly, I convert the string to a char using .ToCharArray() and set the first letter of each word to uppercase. The problem then is I can't figure out how to convert the char array back to a string. Whether I use .ToString() from the...
10
15554
by: Kim Hellan | last post by:
I have a simple string in the format "DD-MM-YY hh:mm:ss", that I need to convert to a DateTime value. I know this is a standard problem, but please don't just link to all the MSDN pages regarding Parse() and ParseExact(). I've been there and read all the information about using IFormatProviders, DateTimeStyles, CultureInfo....... Bottom line is that I can't get it working, so could someone please just post 5-10 lines of working code...
4
11208
by: M. Uppal | last post by:
How do i convert fraction to time in c#. I need to convert 0.25 to time. Excel does this by using Selection.NumberFormat = "h:mm:ss;@" of the Cell Format function. thanks, M. Uppal
1
4452
by: Andrew Baker | last post by:
this seems to be an SQL Server error but I cant work out how it is occuring. Itr is also after 3am and I cant keep working but need to demo by tomorrow. TIA. The code is: Private Sub myMethod(ByVal cust As String, ByVal invDate As Date) Dim paramDate As New OleDb.OleDbParameter, Dim paramCustomer As New OleDb.OleDbParameter paramDate.ParameterName = "@InvDate" paramDate.Value = invDate
8
2490
by: Mika M | last post by:
Is there better way to convert integer type date into DateTime type date as doing like code below? Dim intDate As Integer = 20051019 Dim dte As DateTime = New DateTime( _ CType(intDate.ToString.Substring(0, 4), Integer), _ CType(intDate.ToString.Substring(4, 2), Integer), _ CType(intDate.ToString.Substring(6, 2), Integer))
3
12431
by: NateM | last post by:
How do I convert any given date into a milliseconds value that represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT? Is there an easy way to do this like Date in java? Thanks, Nate
3
10910
by: Rich Robinson | last post by:
Hi, I have a web service method which takes a DateTime type as a parameter. The service is UK based, and the dates are passed in to the service in the UK format dd/MM/yyyy. On a recent install, the web service method will not accept the UK date format, erroring with a System.Argument exception, but would take US formatted dates.
6
4130
by: B.N.Prabhu | last post by:
Hi, I am having a DataTable which one column is in string format now i want to change that one to DataTime. I don't know whether its in datetime format or not i have to check if it is in DateTime Format some times it may in normal string not a DateTime. If it is in any one of the DateTime format then i have to change it as a Specfic format as "21-03-2005 11:34" using C#.Net. If its not in DateTime format then i should give a message.
5
5397
by: BenG | last post by:
Hi. I have a gridview control on a web form (asp.net 2.0) that's bound to a objectDataSource. The objectdatasource which is bound to a class I've written in the DAL to read and update the database. The grid contains three columns - an ID (GUID), a name (string) and a rowversion (timestamp), and the data is passed to/from the page in an instance of a data entity object. When I open the page the grid loads properly, but if I attempt to edit...
2
11184
by: Brian Parker | last post by:
I am beginning to work with VB2005.NET and I'm getting some problems with string formatting converting an application from VB6. VB6 code:- sTradeDate = Format(pArray(4,i Record), "mmddyy") pArray is a variant array containing a date string at pArray(4, iRecord) in the format "yyyy/mm/dd"
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9484
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10350
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7505
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.