472,374 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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.ParseExact("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 8642
Cameron <co*********@hotmail.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.ParseExact("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.com>
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*******@devdex.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.com>
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*******@devdex.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.com>
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
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...
10
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...
4
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
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...
8
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( _...
3
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...
3
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...
6
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...
5
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....
2
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") ...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.