S
Simon Harvey
Hi all,
I'm having a bit of a problem working with dates. My computer is british,
but I'm developing an american application so I therefore need to use american
dates. But I can't get my DateTime object to "act" american.
Let me give an example:
In order to take in an american date, I tell it which culture the date will
be formatted according to:
if(!(DateTime.TryParse(txtAvailableFrom.Text, new CultureInfo("en-US"), DateTimeStyles.None,
out arrivalDate))){
This all works fine and the DateTime interprets the textbox contents correctly
as an American date. The problem comes later when I try and use the date.
For example, when I try and do date.ToString(), it outputs it in the British
format. Now this one isnt a problem because I know how to force it to output
the american format. (Though it is inconvienient - I'd like the DateTime
object to remember or know somehow that its got an American date and output
accordingly)
The real showstopper for me though is when it comes to passing the date to
the database.
I want all the dates passed to the database to be in the American format.
Unfortunately, when I pass the DateTime object as a parameter to my Stored
Procedure the date is getting stored in the british format.
It's like the DateTime intrinsically knows that its in Britain, even though
I forced it to accept an American date.
Can anyone tell me if there's anyway I can force it to act like an American
date both when outputing and more importantly when I pass it to the database?
I need it to forget that its in Britain and get it to start acting American
stylee pronto!
Thanks to anyone who can help. This thing has been driving me crazy for ages.
It's getting to crunch time soon and I'm begining to get worried :-(
Thanks again
Simon
I'm having a bit of a problem working with dates. My computer is british,
but I'm developing an american application so I therefore need to use american
dates. But I can't get my DateTime object to "act" american.
Let me give an example:
In order to take in an american date, I tell it which culture the date will
be formatted according to:
if(!(DateTime.TryParse(txtAvailableFrom.Text, new CultureInfo("en-US"), DateTimeStyles.None,
out arrivalDate))){
This all works fine and the DateTime interprets the textbox contents correctly
as an American date. The problem comes later when I try and use the date.
For example, when I try and do date.ToString(), it outputs it in the British
format. Now this one isnt a problem because I know how to force it to output
the american format. (Though it is inconvienient - I'd like the DateTime
object to remember or know somehow that its got an American date and output
accordingly)
The real showstopper for me though is when it comes to passing the date to
the database.
I want all the dates passed to the database to be in the American format.
Unfortunately, when I pass the DateTime object as a parameter to my Stored
Procedure the date is getting stored in the british format.
It's like the DateTime intrinsically knows that its in Britain, even though
I forced it to accept an American date.
Can anyone tell me if there's anyway I can force it to act like an American
date both when outputing and more importantly when I pass it to the database?
I need it to forget that its in Britain and get it to start acting American
stylee pronto!
Thanks to anyone who can help. This thing has been driving me crazy for ages.
It's getting to crunch time soon and I'm begining to get worried :-(
Thanks again
Simon