Link to home
Start Free TrialLog in
Avatar of ggivati
ggivati

asked on

type mismatch on date function when using LCID 1037

Hi,

I am trying to localize a software written in the US and running as well in Germany and the UK.

The Hebrew Locale (1037) defines date format as dd/mm/yyyy and when writing a simple ASP page as follows, date appears in the same format:

<%
'dtDate=formatdatetime(date(), vbshortdate)
dtDate=date()
%>
<html>

<head>
</head>

<body>

Date is <%=dtDate %>

</body>

</html>

When using the formatdatetime(date(), vbshortdate) the date is displayed as "þ01/þ08/þ2004" and in debugger mode I see it gets transferred in the URL as yyyy/mm/dd. When runing any date function on it I get tyoe mismatch error.

Any ideas how to resolve this ?

BTW, I'm using client and server on the same machine, with default language Hebrew on Win XP.

thanks,

gil.

Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

The other option is to manipulate the date into the format that you want it:


function formatDate(datDate)
  intYear = Year(datDate)
  intMonth = Month(datDate)
  intDay = Day(datDate)
  formatDate = intYear & "/" & intMonth & "/" & intDay
end function

You can change the last line of the function to return whatever format you want.

FtB
A coule of other thoughts:

1) almost all systems understand the format yyyy/mm/dd
2) if you format dd-mmm-yyyy, i.e., 06-Jun-2004, most systems will resolve this unambiguously

FtB
Avatar of ggivati
ggivati

ASKER

I am trying to set LCID to 1037 and this is exactly when the date gets "reversed" from a reason I cannot understand.
Using the formatDate function you suggested may be a workaround but I'm affraid it will affect other behaviour in other pages of the application.

My preference is to try and understand why ASP reverse the date format from dd/mm/yyyy to yyyy/mm/dd when using LCID 1037.  The following code is a very simple reproduction of the problem:

<%
session.LCID=1037
dtDate=formatdatetime(date(), 2)
dtMonth=month(dtDate)
%>
<html>

<head>
</head>

<body>
Date is <%=dtDate %>
Month is <%=dtMonth %>

</body>

</html>

though it seems like a valid code, it gets type mismatch on the month parsing line
Let me run that here so that I can see what you see. Please stand by for a minute.

FtB
Hmn....

SessionID, ASP 0219 (0x80004005)
The specified LCID is not available.
/dev/eesample.asp, line 9
Avatar of ggivati

ASKER

You probably don't have the language installed ...
Here is the code:

<%
session.LCID=1037
dtDate=formatdatetime(date(), 2)
dtMonth=month(dtDate)
%>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
Date is <%=dtDate %>
Month is <%=dtMonth %>
</BODY>
</HTML>


Here is the error:

SessionID error 'ASP 0219 : 80004005'

Invalid LCID

/eesample.asp, line 2

The specified LCID is not available.
I tried in on my XP with IIS and with my hosting server (Win 2K)

FtB
Okay, since I can't see what you see, let's try a slightly different approach...

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<%
dtDate=date()
Response.write("Type Before:" & VarType(dtDate) & "<P>")
dtDate=formatdatetime(date(), 2)
Response.write("Type After" & VarType(dtDate) & "<P>")
dtMonth=month(dtDate)
Response.write("Type Month" & VarType(dtMonth) & "<P>")
%>
</BODY>
</HTML>
Avatar of ggivati

ASKER

You need to have Hebrew installed. it is not installed by default on the server.
Okay, so when I run the above, I get:

Type Before:7
Type After8

Type Month2


7 = vbDate
8=vbString
2=vbInteger

FtB
I suspect what might be happeing here is that the raw date format you end up getting is dependent upon the regional settings of your server.

FtB
Avatar of ggivati

ASKER

I still get a type mismatch on the dtMonth=month(dtDate) line. and dtDate is seen ( in visual studio debugger) "2004/08/01"
>>My preference is to try and understand why ASP reverse the date format from dd/mm/yyyy to yyyy/mm/dd when using LCID 1037.<<

Using the LCID formats the display of your date but does not change the instrinsic format which is actually controlled by the regional settings on the server.

FtB
Avatar of ggivati

ASKER

true, but setting LCID also affects the currency symbol and I will want to have the local currency used.
That is true, but if you are going to run the code in a series of environments, then you will have to do some gymnastics with date manipulation unless all of the servers have the same regional settings.

FtB
With this script;

HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<%
dtDate=date()
Response.write("Type Before:" & VarType(dtDate) & "<P>")
dtDate=formatdatetime(date(), 2)
Response.write("Type After" & VarType(dtDate) & "<P>")
dtMonth=month(dtDate)
Response.write("Type Month" & VarType(dtMonth) & "<P>")
%>
</BODY>
</HTML>


what probably happens is that dtDate=formatdatetime(date(), 2) produces a format that your code no longer understands as a valid date.

FtB
So the only way that you will have the control that you really want is to use the native format for all of the coding and calculations and then use the date function that I gave you above to display things the way that you want to.

FtB
Avatar of ggivati

ASKER

FtB,

Your script did do the work in most parts. I now need to enhance it a bit to accomodate the use of times as well.

10x.

Gl.
This should put you on your way:

function forceDateTimeFormat(datDate)
  intYear = Year(datDate)
  intMonth = Month(datDate)
  intDay = Day(datDate)
  intHour = Hour(datDate)
  intMinute = Minute(datDate)
  intSecond = Second(datDate)
  forceDateTimeFormat= intYear & "/" & intMonth & "/" & intDay & " " & intHour & ":" & intMinute & ":" & intSecond
end function


Fritz the Blank
So, did the last bit do what you needed it to?

FtB
Avatar of ggivati

ASKER

Yes it did. 10x.
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial