Author |
Topic  |
|
bjlt
Senior Member
   
1144 Posts |
Posted - 21 May 2003 : 12:21:06
|
in StrToDate chkDateFormat is used. to my understanding, chkDateFormat is to check if (yyyymmddhhmmss) is mm/dd/yyyy hh:mm:ss (true) or dd/mm/yyyy hhmmss (false), However, I wonder why it's needed in StrToDate, and also why the else part of chkDateFormat in StrToDate . to me, it looks the else part uses the current time, I wonder why if yyyymmddhhmmss is actually yyyyDDMMhhmmss the current time is used. first, how come a date string in snitz become yyyyDDMMhhmmss? second, even though that may happen, what's the purpose to use the current time?
If all the datestring is in the format of yyyymmddhhmmss can I take chkDateFormat out of StrToDate?
Thanks in advance.
function chkDateFormat(strDateTime)
chkDateFormat = isdate("" & Mid(strDateTime, 5,2) & "/" & Mid(strDateTime, 7,2) & "/" & Mid(strDateTime, 1,4) & " " & Mid(strDateTime, 9,2) & ":" & Mid(strDateTime, 11,2) & ":" & Mid(strDateTime, 13,2) & "")
end function
function StrToDate(psDateTime)
Dim tmpDate
if ChkDateFormat(psDateTime) then
'## Testing for server format
if strComp(Month("04/05/2002"),"4") = 0 then '## server format: mm/dd/yyyy
StrToDate = cdate("" & Mid(psDateTime, 5,2) & "/" & Mid(psDateTime, 7,2) & "/" & Mid(psDateTime, 1,4) & " " & Mid(psDateTime, 9,2) & ":" & Mid(psDateTime, 11,2) & ":" & Mid(psDateTime, 13,2) & "")
else '## server format: dd/mm/yyyy
StrToDate = cdate("" & Mid(psDateTime, 7,2) & "/" & Mid(psDateTime, 5,2) & "/" & Mid(psDateTime, 1,4) & " " & Mid(psDateTime, 9,2) & ":" & Mid(psDateTime, 11,2) & ":" & Mid(psDateTime, 13,2) & "")
end if
else
if strComp(Month("04/05/2002"),"4") = 0 then '## server format: mm/dd/yyyy
tmpDate = DatePart("m",sTimeAdjust) & "/" & DatePart("d",sTimeAdjust) & "/" & DatePart("yyyy",sTimeAdjust) & " " & DatePart("h",sTimeAdjust) & ":" & DatePart("n",sTimeAdjust) & ":" & DatePart("s",sTimeAdjust)
else '## server format: dd/mm/yyyy
tmpDate = DatePart("d",sTimeAdjust) & "/" & DatePart("m",sTimeAdjust) & "/" & DatePart("yyyy",sTimeAdjust) & " " & DatePart("h",sTimeAdjust) & ":" & DatePart("n",sTimeAdjust) & ":" & DatePart("s",sTimeAdjust)
end if
StrToDate = tmpDate
end if
end function
|
Edited by - bjlt on 21 May 2003 13:40:49 |
|
bjlt
Senior Member
   
1144 Posts |
Posted - 21 May 2003 : 12:40:21
|
hmm, is the codes in question there in case of the code below may be called?
function DateToStr(pdtDateTime) '# okyx1
if not isDate(pdtDateTime) then
dtDateTime = strToDate(pdtDateTime)
end if
? |
Edited by - bjlt on 21 May 2003 13:33:26 |
 |
|
OneWayMule
Dev. Team Member & Support Moderator
    
Austria
4969 Posts |
|
bjlt
Senior Member
   
1144 Posts |
Posted - 21 May 2003 : 13:30:55
|
Thanks OneWayMole. 
I know what it does, however, I wonder why the codes in question are there.
|
 |
|
masterao
Senior Member
   
Sweden
1678 Posts |
|
bjlt
Senior Member
   
1144 Posts |
Posted - 22 May 2003 : 00:06:22
|
masterao, thanks. that topic is locked and I sitll have questions on it.
when will ChkDateFormat return false in snitz? I think strToDate will make all datestring in yyyymmddhhmmss format no matter what locale is used.
What's the solution for the int'l version? I've some codes here which could be used in the int'l version. Would someon like to test it? Please back up your existing code.
'## output 14-digit date string in db to date type according to locale.
function StrToDate(psDateTime)
if isnull(psDateTime) or psDateTime = "" then StrToDate = null : Exit Function
Dim iLen
iLen = len(psDateTime)
if iLen = 8 then psDateTime = psDateTime & "000000"
if iLen <> 8 and iLen <> 14 then StrToDate = null : Exit Function
'## Testing for locale format
if strComp(Month("04/05/2002"),"4") = 0 then '## locale format: mm/dd/yyyy
StrToDate = cdate("" & Mid(psDateTime, 5,2) & "/" & Mid(psDateTime, 7,2) & "/" & Mid(psDateTime, 1,4) & " " & Mid(psDateTime, 9,2) & ":" & Mid(psDateTime, 11,2) & ":" & Mid(psDateTime, 13,2) & "")
else '## locale format: dd/mm/yyyy
StrToDate = cdate("" & Mid(psDateTime, 7,2) & "/" & Mid(psDateTime, 5,2) & "/" & Mid(psDateTime, 1,4) & " " & Mid(psDateTime, 9,2) & ":" & Mid(psDateTime, 11,2) & ":" & Mid(psDateTime, 13,2) & "")
end if
end function
'## date to 14-digits date string
function DateToStr(pdtDateTime)
if not isDate(pdtDateTime) then
pdtDateTime = StrToDate(pdtDateTime)
end if
if isnull(pdtDateTime) then DateToStr = null : Exit Function
DateToStr = year(pdtDateTime) & doublenum(Month(pdtdateTime)) & doublenum(Day(pdtdateTime)) & doublenum(Hour(pdtdateTime)) & doublenum(Minute(pdtdateTime)) & doublenum(Second(pdtdateTime)) & ""
end function
'## yx: output date to format defined in locale
'## yx: sDate, piDateFormat: -1 not 0 vbGeneralDate 1 long 2 short, piTimeFormat: -1 not 3 long 4 short
function ShowDate(psDate,piDateFormat,piTimeFormat)
ShowDate = ""
if not isDate(psDate) then
if isnull(psDate) or psDate = "" then ShowDate = "N/A" : exit function
Dim iLen
iLen = Len(psDate)
if iLen <> 8 and iLen <> 14 then ShowDate = "N/A" : exit function
if iLen = 8 then psDate = psDate & "000000"
psDate = StrToDate(psDate)
end if
if piDateFormat = 0 then piTimeFormat = -1
if piDateFormat = 0 or piDateFormat = 1 or piDateFormat = 2 then
ShowDate = FormatDateTime(psDate, piDateFormat)
end if
if piTimeFormat = 3 or piTimeFormat = 4 then
ShowDate = ShowDate & " " & FormatDateTime(psDate,piTimeFormat)
end if
end function
|
 |
|
bjlt
Senior Member
   
1144 Posts |
Posted - 22 May 2003 : 00:15:04
|
to test it save it as a file with the related functions in it. using filename.asp?lan=lancode to change the locale and test
<%@ codepage = 65001%>
<%
Response.Charset = "utf-8"
%>
<SCRIPT Runat=Server Language=VBScript>
Sub SetLCID()
Dim strAcceptLanguage
Dim strLCID
Dim strPos
strAcceptLanguage = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
strPos = InStr(1, strAcceptLanguage, ",")
If strPos > 0 Then
strAcceptLanguage = Left(strAcceptLanguage, strPos - 1)
End If
strAcceptLanguage = trim(Request.QueryString("lan"))
Select Case LCase(strAcceptLanguage)
'# AR
Case "ar-sa"
strLCID = 1025 ' Arabic(Saudi Arabia)
Case "ar-iq"
strLCID = 2049 ' Arabic(Iraq)
Case "ar-eg"
strLCID = 3073 ' Arabic(Egypt)
Case "ar-ly"
strLCID = 4097 ' Arabic(Libya)
Case "ar-dz"
strLCID = 5121 ' Arabic(Algeria)
Case "ar-ma"
strLCID = 6145 ' Arabic(Morocco)
Case "ar-tn"
strLCID = 7169 ' Arabic(Tunisia)
Case "ar-om"
strLCID = 8193 ' Arabic(Oman)
Case "ar-ye"
strLCID = 9217 ' Arabic(Yemen)
Case "ar-sy"
strLCID = 10241 ' Arabic(Syria)
Case "ar-jo"
strLCID = 11265 ' Arabic(Jordan)
Case "ar-lb"
strLCID = 12289 ' Arabic(Lebanon)
Case "ar-kw"
strLCID = 13313 ' Arabic(Kuwait)
Case "ar-ae"
strLCID = 14337 ' Arabic(U.A.E.)
Case "ar-bh"
strLCID = 15361 ' Arabic(Bahrain)
Case "ar-qa"
strLCID = 16385 ' Arabic(Qatar)
'# ZH
Case "zh-tw"
strLCID = 1028 ' Chinese(Taiwan)
Case "zh-cn"
strLCID = 2052 ' Chinese(PRC)
Case "zh-hk"
strLCID = 3076 ' Chinese(Hong Kong)
Case "zh-sg"
strLCID = 4100 ' Chinese(Singapore)
'# EN
'Case "en"
' strLCID = 9 ' English
Case "en-us"
strLCID = 1033 ' English(United States)
Case "en-gb"
strLCID = 2057 ' English(British)
Case "en-au"
strLCID = 3081 ' English(Australian)
Case "en-ca"
strLCID = 4105 ' English(Canadian)
Case "en-nz"
strLCID = 5129 ' English(New Zealand)
Case "en-ie"
strLCID = 6153 ' English(Ireland)
Case "en-za"
strLCID = 7177 ' English(South Africa)
Case "en-jm"
strLCID = 8201 ' English(Jamaica)
'Case "en"
' strLCID = 9225 ' English(Caribbean)
Case "en-bz"
strLCID = 10249 ' English(Belize)
Case "en-tt"
strLCID = 11273 ' English(Trinidad)
'# FR
Case "fr"
strLCID = 1036 ' French(Standard)
Case "fr-be"
strLCID = 2060 ' French(Belgian)
Case "fr-ca"
strLCID = 3084 ' French(Canadian)
Case "fr-ch"
strLCID = 4108 ' French(Swiss)
Case "fr-lu"
strLCID = 5132 ' French(Luxembourg)
'# DE
Case "de"
strLCID = 1031 ' German(Standard)
Case "de-ch"
strLCID = 2055 ' German(Swiss)
Case "de-at"
strLCID = 3079 ' German(Austrian)
Case "de-lu"
strLCID = 4103 ' German(Luxembourg)
Case "de-li"
strLCID = 5127 ' German(Liechtenstein)
'# IT
'Case "it"
' strLCID = 1040 ' Italian(Standard)
'Case "it-ch"
' strLCID = 2064 ' Italian(Swiss)
'# JA
Case "ja"
strLCID = 1041 ' Japanese
'# KO
Case "ko"
strLCID = 1042 ' Korean
Case "ko"
strLCID = 2066 ' Korean(Johab)
'# PT
'Case "pt-br"
' strLCID = 1046 ' Portuguese(Brazil)
'Case "pt"
' strLCID = 2070 ' Portuguese(Portugal)
'# RU
Case "ru"
strLCID = 1049 ' Russian
Case "ru-mo"
strLCID = 2073 ' Russian(Moldavia)
'# ES
Case "es"
strLCID = 1034 ' Spanish(Spain - Traditional Sort)
Case "es-mx"
strLCID = 2058 ' Spanish(Mexican)
Case "es"
strLCID = 3082 ' Spanish(Spain - Modern Sort)
Case "es-gt"
strLCID = 4106 ' Spanish(Guatemala)
Case "es-cr"
strLCID = 5130 ' Spanish(Costa Rica)
Case "es-pa"
strLCID = 6154 ' Spanish(Panama)
Case "es-do"
strLCID = 7178 ' Spanish(Dominican Republic)
Case "es-ve"
strLCID = 8202 ' Spanish(Venezuela)
Case "es-co"
strLCID = 9226 ' Spanish(Colombia)
Case "es-pe"
strLCID = 10250 ' Spanish(Peru)
Case "es-ar"
strLCID = 11274 ' Spanish(Argentina)
Case "es-ec"
strLCID = 12298 ' Spanish(Ecuador)
Case "es-c"
strLCID = 13322 ' Spanish(Chile)
Case "es-uy"
strLCID = 14346 ' Spanish(Uruguay)
Case "es-py"
strLCID = 15370 ' Spanish(Paraguay)
Case "es-bo"
strLCID = 16394 ' Spanish(Bolivia)
Case "es-sv"
strLCID = 17418 ' Spanish(El Salvador)
Case "es-hn"
strLCID = 18442 ' Spanish(Honduras)
Case "es-ni"
strLCID = 19466 ' Spanish(Nicaragua)
Case "es-pr"
strLCID = 20490 ' Spanish(Puerto Rico)
Case Else
strLCID = 2048 ' default
End Select
Session.LCID = strLCID
End Sub
</SCRIPT>
<%
SetLCID
sDate = "2003/5/11 13:13:13"
'Response.Write sDate
Response.Write "Date/Time Formats"
Response.Write Month("04/05/2002") & "<br>"
Response.Write FormatDateTime(sDate,0) & "<br>"
Response.Write FormatDateTime(sDate,1) & "<br>"
Response.Write FormatDateTime(sDate,2) & "<br>"
Response.Write FormatDateTime(sDate,3) & "<br>"
Response.Write FormatDateTime(sDate,4) & "<br>"
Response.Write "<p>Date = " & Date()
Response.Write "<br>Month = " & Month(Date())
Response.Write "<br>Day = " & Day(Date())
Response.Write "<br>Year = " & Year(Date())
Response.Write "<br>Time = " & Time()
Response.Write "<p>Currency Formats"
Response.Write "<p>" & FormatCurrency(-100000.0503, 2)
Response.Write "<br>" & FormatNumber(1000000,2)
Response.Write "<br>" & FormatNumber(-1000000,2)
Response.Write "<br>" & FormatPercent(-212/321882)
Response.Write "<br>" & showdate("20030512131313",1,3)
Response.Write "<br>" & showdate("20030512131313",0,0)
Response.Write "<br>" & showdate("20030512131313",1,0)
Response.Write "<br>" & showdate("20030512131313",2,0)
Response.Write "<br>" & showdate("20030512131313",2,3)
Response.Write "<br>" & showdate("20030512131313",2,4)
Response.Write "<br>" & showdate("20030512131313",1,4)
Response.Write "<br>" & showdate("20030512",1,3)
Response.Write "<br>" & showdate("20030512",0,0)
Response.Write "<br>" & showdate("20030512",1,0)
Response.Write "<br>" & showdate("20030512",2,0)
Response.Write "<br>" & showdate("20030512",2,3)
Response.Write "<br>" & showdate("20030512",2,4)
Response.Write "<br>" & showdate("20030512",1,4)
Response.Write "<br>" & showdate(now,1,3)
Response.Write "<br>" & showdate(now,0,0)
Response.Write "<br>" & showdate(now,1,0)
Response.Write "<br>" & showdate(now,2,0)
Response.Write "<br>" & showdate(now,2,3)
Response.Write "<br>" & showdate(now,2,4)
Response.Write "<br>" & showdate(now,1,4)
Response.Write "<br>" & showdate("2003/05/12 13:13:13",1,3)
Response.Write "<br>" & showdate("2003/05/12 13:13:13",0,0)
Response.Write "<br>" & showdate("2003/05/12 13:13:13",1,0)
Response.Write "<br>" & showdate("2003/05/12 13:13:13",2,0)
Response.Write "<br>" & showdate("2003/05/12 13:13:13",2,3)
Response.Write "<br>" & showdate("2003/05/12 13:13:13",2,4)
Response.Write "<br>" & showdate("2003/05/12 13:13:13",1,4)
c = DateToStr("05/122003")
d = StrToDate("2003")
if isnull(c) then c = "null"
if isnull(d) then d = "null"
Response.Write "DateToStr=" & c
Response.Write "StrToDate=" & d
%>
|
Edited by - bjlt on 22 May 2003 00:30:10 |
 |
|
HuwR
Forum Admin
    
United Kingdom
20600 Posts |
Posted - 22 May 2003 : 05:15:56
|
is there something wrong with the way it currently does it ? |
 |
|
bjlt
Senior Member
   
1144 Posts |
Posted - 22 May 2003 : 06:01:50
|
not really. Intitially I have question on the code 1 when will ChkDateFormat return false in snitz? i.e. when the datestring to be checked is in yyyyDDMM.... format? Maybe it's for backward compatibility. Then why it uses strAdjustForumtime, which is the current time actually, in that case? To me it seems when a wrong datestring is found it just shows the current time .
Later in the posts I have some codes related to share for the int'l version, however it's not tested and I'm not sure if it works well in int'l version yet, and like to see others opinions on it.
I remember bozden mentioned LCID will be used for the int'l version. and my codes use LCID so I put it here to share.
edit: minor grammartical fix.
|
Edited by - bjlt on 22 May 2003 06:14:10 |
 |
|
HuwR
Forum Admin
    
United Kingdom
20600 Posts |
Posted - 22 May 2003 : 06:32:23
|
quote:
1 when will ChkDateFormat return false in snitz?
If there is something wrong with the date, in which case it sets it to now so there are no problems with dodgy dates. And yes it is there for compatability as this used to be a big problem on non us dated servers.
|
 |
|
bjlt
Senior Member
   
1144 Posts |
Posted - 22 May 2003 : 07:11:36
|
Thanks HuwR, now I'm clear on this. 
|
 |
|
|
Topic  |
|
|
|