Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I make vbscript give me British dates?

Status
Not open for further replies.

LucyP

Programmer
Jan 17, 2001
51
ES
This problem has been driving me mad for months:

Everything on my computer is set to British English, including my SQL Server and the regional settings in Windows 2000 - all dates appear as dd/mm/yyyy

Whenever I use "Date()" in VBscript though (this is in ASP running on IIS) I get an American format date (mm/dd/yyyy) which causes errors galore.

What could I have missed? Does IIS have it's own date settings? Are there any settings in VB itself?
 
Hi,

You can format the date in the script using something like:

Code:
<%
 Dim CurrMonth, CurrDay, CurrYear, CurrDate
 CurrYear = Year(Date())
 CurrMonth = Month(Date())
 CurrDay = Day(Date())
 CurrDate = CurrDay & &quot;/&quot; & CurrMonth & &quot;/&quot; & CurrYear
 response.write CurrDate
%>

Bye.
 
still having problems!

This is all very well, but a bit of a pain. Also in order to use DateAdd with months you have to convert the dates and then convert them back again. Surely there is a way!
 
You also need to change the locales on your SQL server.

(go into regional settings and click set default, this may still be set to america).
 
You should look into Session.LCID... This is not a bug - it's an undocumented feature...
;-)
 
There are 2 sollutions, first you can change the sql server authentication (secutity - Logins) if you set the language to Dutch (as I am) the date automatically will be set to dd-mm-yyyy format if your application uses this account to log in.
Second one is make sure the client supplies the date in UK format like:
date = month(mydate) & &quot;/&quot; & day(mydate) & &quot;/&quot; year(mydate)
Use some java applet or mscal.ocx to fill out a disabled textfield so the user can see the date and put the UK date in a hidden textbox. When it is submitted use the hidden textbox for your SQL statement.
 
Got some time to give you a good sample:
First you download a calendar applet here you can do this:
Here is the code (you need IIS to run the asp page)
The html page:
<script language=&quot;javascript&quot;>
window.focus();
</script>
<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;>
<form name=beamer action=beamerlist.asp>
<tr>
<td bgColor=#98cecb onclick=&quot;window.open('testdate.asp?CtlName=1&startdate=' + strt1.value , 'MSWindow', 'menubar=no,width=350,height=250');&quot; title=&quot;Click here to change the start date/time&quot; style=&quot;cursor: hand&quot;>
<label id=starttimedate1 name=starttimedate1>08 December 2001 16:36</label>
<input type=hidden value=&quot;08 December 2001 16:36&quot; name=strt1 id=strt1>
</td>
</tr>
<table>

The asp page:
<script language=&quot;JavaScript&quot;>
window.focus();
</script>
<script language=&quot;vbscript&quot;>
function seeDate()
i = document.tL2.getDate()
window.opener.document.forms(0).elements(&quot;strt<%=Request.QueryString(&quot;CtlName&quot;)%>&quot;).value = month(i) & &quot;/&quot; & Day(i) & &quot;/&quot; & year(i) & &quot; &quot; & thetime.value
window.opener.document.all.item(&quot;starttimedate<%=Request.QueryString(&quot;CtlName&quot;)%>&quot;).innerText = Day(i) & &quot; &quot; & monthname(month(i)) & &quot; &quot; & year(i) & &quot; &quot; & thetime.value
window.close()
end function
</script>
<center>
<applet code=tcaldate.class width=160 height=170 NAME=&quot;tL2&quot; ID=&quot;tL2&quot; MAYSCRIPT>
<param name=link value=&quot;%M/%D/%Y&quot;>
<param name=script value=&quot;javascript:seeDate()&quot;>
<param name=target value=&quot;_none&quot;>
<param name=startsunday value=&quot;0&quot;>
<param name=font value=&quot;Arial&quot;>
<param name=fontsize value=12>
<param name=fontstyle value=1>
<param name=bgcolor value=13684944>
<param name=bgcolor2 value=14737663>
<param name=bgcolor3 value=400>
<%
if request(&quot;startdate&quot;) <> &quot;&quot; then
tme = request(&quot;startdate&quot;)
tme = mid(tme,1,len(tme)-6)
tme = month(tme) & &quot;/&quot; & day(tme) & &quot;/&quot; & year(tme)
else
tme = now()
tme = mid(tme,1,len(tme)-6)
tme = month(tme) & &quot;/&quot; & day(tme) & &quot;/&quot; & year(tme)
end if
%>
<param name=current value=<%=tme%>>
<param name=t_col1 value=400>
<param name=t_col2 value=8421520>
<param name=t_col3 value=14737663>
</applet><br>
<%
tme = request(&quot;startdate&quot;)
tme = mid(tme,len(tme)-4,5)
%>
<font style=&quot;size: x-small&quot;>Time: </font><input type=text name=thetime value=<%=tme%> style=&quot;width: 50px&quot;><input type=button onclick=&quot;seeDate();&quot; value=&quot; OK &quot;>
</center>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top