ASP date problems.

T

TC

Hi.

I have some ASP written in VB.net which is currently installed on a
customers server. The asp connects to a local MySql database and retrieves
data for the customers customers. If you see what I mean.

The problem is their server insists on showing dates in the US format. The
server has no other language installed than UK and all settings I can find
are UK.

My test server here, which as far as I can see is setup the same, shows
dates in the correct UK format.

Has anyone come accross this, or have any ideas?

Cheers.
 
C

Claes Bergefall

Could be a number of reasons for this, the first that comes to mind is that
the web server account has the wrong regional info.

I few questions:

What code are you using to format the dates?
Are you using the <globalization> element in your web.config (and if so, how
is it set)?
Is the US format consistant across different browsers/machines?

/claes
 
T

TC

I'm not really using anything to format the dates, the return from MySql is,
as far as I know, the international format, so it's hh:mm:ss yyyy/mm/dd.
For putting data in the grid I'm simply looking for the " " (Space char) and
returning the right of the string.

Yes, it is repeated over any browser or client connection so the issue has
to be server side.

The Web Server account? The user account that controls access to the web
site?

I'm a little new to this technology so any help would be very much
appreciated.

Cheers.
 
T

TC

I've had a look at the Web.Config file, but can't see anything in there for
date formats or globalization, maybe this is the problem. What should I be
looking for?

Cheers.
 
T

TC

I've just changed the code so I'm forcing the culture to en-NZ, there
doesn't appear to be an en-UK setting. However NZ gives the same date
format required. However, again it works on my server, not on the
customers. I'm confused!
 
J

John Whitmore

I could be off base but this might help.

'Make sure date time data between workstations and SQL does not
'get fouled up by users changing language settings or system time.
'we had one user using system time as a reference calendar.
Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-US")
This allows them to do what they want on their client stations but tells the
assembly what culture info you want to work with when you use a format
function. In this case it is set to en-US you should be able to set this to
en-UK. This lets Microsoft do the culture conversion. It does not affect
anything outside the assembly but will convert date type data from from what
ever culture it is in to the one you want to use for your assembly.
 
C

Claes Bergefall

I'm not familiar with MySQL but I would expect the data to be stored using
some kind of datetime data type and not as text. In SQL Server you would use
smalldatetime or datetime to store a date and then work with the .NET
DateTime datatype in your ASP.NET pages. Once you have a DateTime object you
would use it's ToString method to format it in whatever way you want (see
DateTime.ToString)

If it's really stored as text and you simply extract the right part of the
string then I don't see any way for it to change format to US. If that is
the case the problem is in the MySQL server. You need to verify what
datatype is used and what it looks like. It would help if you could show the
code you're using to get the date from the database.

The <globalization> tag in web.config allows the web server to provide
formating according to the user's preferences. It gets this information from
the client browser (e.g. in IE you can specify what language you prefer in
the options). However, this only works if you're using real date types, so
figure out the things above first and you can deal with this step later
(it's entirely optional anyway)

As for the account thing; the process that hosts your ASP.NET application on
the web server (I'm guessing IIS?) runs under it's own account called ASPNET
(or something like that). That account has it's own settings regarding
security, culture info etc. If the machine was installed using a UK version
on Windows it most likely has the correct settings already.

/claes
 
T

TC

I think the problem is more fundamental that the Cultures, I'm not convinced
the customers server is setup all that well. The ASP is running on the same
server as the MySql Data server.

The server handles many processes collected through a 485 scanner network
and puts data into the database, this is all time stamped correctly.

The server also stores outgoing Email messages, these are polled on a daily
basis and there is no problem with any date in any mail.

There is also software on the server, part of this whole installation that
interogates the database, all dates are returned correctly. Obviously if a
client changes their settings they get date data the wrong way around, but I
always force dates going into the database to be yyyy/MM/dd so there can't
be any problems with the stored data.

It only appears to be the ASP running on the server that is at fault. I
can't see any difference in the way IIS is installed and setup on the
customers server to mine. My server behaves as I would expect, dates are
returned according to the IE client. The customers server will only return
m/d/yyyy, no matter what the client is set for.

I'm almost ready to go out and re-install their server!
 
T

TC

No, the date is stored as a date, MySql basically uses 00:00:00 yyyy/MM/dd
as standard. So I've been pulling the date time from the database and
formatting text simply to remove anything left of the space char. So the
date format is already wrong before I do any formating.

I have tried forcing the culture, forcing a Format("dd/MM/yyyy", dte) but it
still shows US format of M/d/yyyy.

I'm beggining to think there is a problem with this server!
 
A

Andrew Morton

TC said:
I've just changed the code so I'm forcing the culture to en-NZ, there
doesn't appear to be an en-UK setting.

It would be en-gb, not en-uk.

For an Access db, you can specify the locale in the connection string, e.g.:

"Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.mdb;Locale
Identifier=2057;Uid=Admin;Pwd=;"

....maybe you can find similar for mySql.

Andrew
 
C

Claes Bergefall

TC said:
No, the date is stored as a date, MySql basically uses 00:00:00 yyyy/MM/dd
as standard. So I've been pulling the date time from the database and
formatting text simply to remove anything left of the space char. So the
date format is already wrong before I do any formating.

This doesn't make sense. If the date is stored in the database using a real
date type then where are you getting the string 00:00:00 yyyy/MM/dd from?
Who created that string? What kind of data type do you have on the .NET side
of things?

I looked into MySQL a bit more and I noticed they have an ADO.NET library
with a MySqlDateTime type. Is this what you're using? If so you should be
able to get a real .NET DateTime object using the MySqlDateTime.GetDateTime
method. Once you have that it's a simple thing to format it the way you
want.

It would help if you could show us the code you're using to get the dates
from the database and also how you're formatting the output.

I have tried forcing the culture, forcing a Format("dd/MM/yyyy", dte) but
it still shows US format of M/d/yyyy.

Is this .NET code? What's the datatype of the dte parameter?

I'm beggining to think there is a problem with this server!

Well, it looks like the server is not setup exactly the same way as your
test server. On the other hand I also think there is a problem with your
code in the way it handles dates.


/claes
 

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

Top