Dates

G

Guest

Hello all,

we have an app with works across the globe, and therefore dates are
displayed in a number of formats, such as dd/MM/yyyy (uk) and MM/dd/yyyy
(usa). When our app has it's language set to ENGLISH everything works fine,
but when it's set to AMERICAN the dates fail as we're trying to cast a date
such as 16/04/2007 to a US DateTime.

What I need to know is, no matter what culture/language you're in how do you
cast the dates a date dd/MM/yyyy.

Thanks,

Jon
 
M

Mark Rae

Jon said:
Hello all,

we have an app with works across the globe, and therefore dates are
displayed in a number of formats, such as dd/MM/yyyy (uk) and MM/dd/yyyy
(usa). When our app has it's language set to ENGLISH everything works
fine,
but when it's set to AMERICAN the dates fail as we're trying to cast a
date
such as 16/04/2007 to a US DateTime.

What I need to know is, no matter what culture/language you're in how do
you
cast the dates a date dd/MM/yyyy.

DateTime MyDateTime = <get your date from somewhere>;
MyLabel.Text = MyDateTime.ToString("dd/MM/yyyy");

However, UNDER NO CIRCUMSTANCES should you use this date format in an
international application!!!

The reason is fairly obvious - it's ambiguous...

E.g. what date is this: "04/02/2004"? You may know exactly what date it is
but, depending on where the client lives, it will be seen as either 4th
February or 2nd April.

Use a three-digit month, and you'll never have any ambiguity.
 
K

Kees de Winter

You may want to read up on System.Globalization.DateTimeFormatInfo

e.g.
Dim dtfi As New System.Globalization.DateTimeFormatInfo
dtfi.ShortTimePattern = "M/d/yyyy"
Dim theDate As Date = Convert.ToDateTime(SomeDateString, dtfi)

Kees
 
R

Rad [Visual C# MVP]

Hello all,

we have an app with works across the globe, and therefore dates are
displayed in a number of formats, such as dd/MM/yyyy (uk) and MM/dd/yyyy
(usa). When our app has it's language set to ENGLISH everything works fine,
but when it's set to AMERICAN the dates fail as we're trying to cast a date
such as 16/04/2007 to a US DateTime.

What I need to know is, no matter what culture/language you're in how do you
cast the dates a date dd/MM/yyyy.

Thanks,

Jon

You can save a lot of time (and code) by setting the website's culture at
web.config level to en-GB
 
A

Alvin Bruney [MVP]

No, you don't want to do that because it is a web application. Instead
prefer a tostring(MM/dd/YYYY) formatter overload after you have the date.
For web applications you absolutely cannot force a web app to live in one
culture. You want to pick up localization off the request object and adjust
the output accordingly.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
 
M

Mark Rae

No, you don't want to do that because it is a web application. Instead
prefer a tostring(MM/dd/YYYY) formatter overload after you have the date.

What date is 04/02/2007?
 
R

Rad [Visual C# MVP]

No, you don't want to do that because it is a web application. Instead
prefer a tostring(MM/dd/YYYY) formatter overload after you have the date.
For web applications you absolutely cannot force a web app to live in one
culture. You want to pick up localization off the request object and adjust
the output accordingly.

I think it depends on circumstances. An international application of course
is one thing but if you know your audeince setting a global culture is a
perfectly good workaround that doesn't even require changing your code
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top