Date format in AM/PM after changing all registry values to yyyy-MM-dd

Hi,

I'm new to EE and hope I can get an answer to this question. We have migrated our system, Windows 2003 Server, to new servers. Unfortunately they wers set up with the default setting M/d/yyyy. I have changed all values in the registry to yyyy-MM-dd for all users in control panel > International.
Still the wrong date is displayed on the web site. The time is correct as 24 hours.

How shall I be able to change to the ODBC Timestamp format yyyy-MM-dd? I have searched the registry and there is no key with the value M/d/yyyy. I don't want to set the locale to e.g. Swedish because of the risk to get commas as decimal separators.

I am appreciated for any help.

Thanks in advance

Lage
spoonplayerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sammySeltzerCommented:
dnow = date()
sdate = split(DateAdd("sdate ",1,d_dnow),"/")
fdate = sdate(2) & "-" & sdate(0) & "-" & sdate(1)

response.write fdate
0
sammySeltzerCommented:
You can also use a function:

<%
'format a number with the correct amount of digits eg: 9 becomes 09 but 11 stays 11'

Function formatdate(value, digits)
    if digits > len(value) then
        formatdate= String(digits-len(value),"0") & value
    else
        formatdate= value
    end if
End Function

'test it"'

 response.write Year(date) &  "-" & _
 formatdate(Month(date),2) & _
 "-" & formatdate(Day(date),2)
 %>
0
spoonplayerAuthor Commented:
Thank you sammyselzer for your answer. Unfortunately this is not the problem. I need to set the date format to be sure that the database not mix UK dates as d/M/yyyy with US date M/d/yyyy.

I have functions formatting the date that is viewed. So I want the Now() function return yyyy-MM-dd in unformatted date.

Thank you


Lage
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

sammySeltzerCommented:
Sorry if I misunderstood you.

I am still not clear what you want.

Are you saying you want to format in M/d/yyyy?

If that's the case, then the code I posted would still work; just a little tinkling.

<%
'format a number with the correct amount of digits eg: 9 becomes 09 but 11 stays 11'

Function formatdate(value, digits)
    if digits > len(value) then
        formatdate= String(digits-len(value),"0") & value
    else
        formatdate= value
    end if
End Function

'test it"'

 response.write formatdate(Month(now()),0) &  "/" & _
 formatdate(Day(now()),2) & _
 "/" & Year(now())
 %>

Open in new window

0
spoonplayerAuthor Commented:
Hi Sammyseltzer,

Thank you again for your answer. Maybe I was not clear in my question. The question is how I could set the date format in the registry so that an unformatted date will be in the format of yyyy-MM-dd in classic asp. I will be absolutely shure that the database not can mix up the two dateformats UK d/M/yyyy and US M/d/yyyy. The ODBC Timestamp format yyyy-MM-dd cannot be mixed up with anything else.

Maybe it's not possible, that the date format is part of vbscript in asp?

So the question is not about the formatting in asp how it is viewed on the web site, but how the date format is handled internally in the system.

Lage
0
sammySeltzerCommented:
Sorry, Lage.

I *think* I understand you now.

You would like your date format styled as yyyy-mm-dd permanently, perhaps by being set in the registry, right?

I am not sure you can do that in the registry but I know you can do it by setting this international local ID at the top of your page as:

<%@ LCID=1053 %>

1053 represents date format of yyyy-mm-dd.

Doesn't matter how it is stored in the db, as long as you have this at the top of your asp page, it will be displayed in that format.

Please let me know if I am still not getting it.
0
spoonplayerAuthor Commented:
Yes, I want to do it in the registry, but I don't want LCID=1053. This will set the decimals as comma which also is a risk screwing up the database input even worser. Comma (,) is a separator between fields in SQL.

Lage
0
sammySeltzerCommented:
Well, there are some resources online on how to change the date format on the registry.

Below are just 2 of those.

http://ss64.com/nt/date.html

http://www.codeproject.com/Tips/169131/Change-System-Date-Format-At-Runtime

The question I have though is, "are you the only consumer of this product?

In other words, if other users are going to be accessing your site or page, do they have to set their registry similarly in other to have similar date format?
0
sybeCommented:
> I don't want to set the locale to e.g. Swedish because of the risk to get commas as decimal separators.

But you can easily set the locale back-and forward in code

<%
iOldLocale = SetLocale(newvalue)
Response.write FormatDateTime(yourdate)
SetLocale(iOldLocale)
%>


> So I want the Now() function return yyyy-MM-dd in unformatted date.

There is no such thing as an unformatted date. Date as such does not get written, but it is always a string that gets written. There is an implicit conversion from (sub)type Date to (sub)type String.


> I need to set the date format to be sure that the database not mix UK dates as d/M/yyyy with US date M/d/yyyy.

Well, the surest way is not to depend on any generic setting, is to simply write a function that does this:

MyDateString = Year(myDate) & "-" & Month(myDate) & "-" & Day(myDate)

At least that is how I do it (after years of experimenting with settings and other solutions). The thing is that settings are really confusing, as there are many settings at many levels. The machine has its settings, the database has its own (separate) settings, IIS has its own settings, and then you can change the settings in your code on more than one way. There is no way that poking around in those settings will produce code that will run on every machine and every database.

See also: http://www.experts-exchange.com/Q_20424961.html


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.