Hi everybody:
I really need to convert Persian date into Gregorian date in a coldfusion.
I found an ASP date convertor and I hope someone help me that I convert it to
CFM. At the end of the message I paste the code and I hope you help me.
I can't use the CFC that is available (perisiancalnedar written by Paul
Hastings) because if I use it I have to install some .jar files in the server
and restart the coldfusion server while I use a sharing server and I am not
sure they accept to retsrat the server for me. Plus anytime I use it in my
local server on my own computer I face a new error. If you any easy way for
setting this CFC it will be great too.
Thanks
Benign
<html>
<head>
<title>date</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
Dim strDate, strDateType, DateParam, strDateConverted
strDate=trim(Request.Form("txtDate"))
strDateType=trim(Request.Form("cboDate"))
DateParam=strDate
if strDateType="English" then
strDateConverted=ChangeToEnglish(DateParam)
elseif strDateType="Persian" then
strDateConverted=ChangeToPersian(DateParam)
end if
Function ChangeToEnglish(DateParam)
DateParam = trim(DateParam)
Y = cInt(Left(DateParam, InStr(DateParam, "/") - 1))
M = cInt(Mid(DateParam, InStr(DateParam, "/") + 1, InStrRev(DateParam, "/")
- InStr(DateParam, "/") - 1))
D = cInt(Mid(DateParam, InStrRev(DateParam, "/") + 1))
If Y < 1300 Then Y = Y + 1300
English Y, M, D
ChangeToEnglish = CStr(DateSerial(Y, M, D))
End Function
Sub English(Y, M, D)
'******************* Leap year
If Y = 1302 OR Y = 1306 OR Y = 1310 OR Y=1314 OR Y=1318 OR Y=1322 OR Y=1326
OR Y = 1330 OR Y=1334 OR Y=1338 OR Y=1342 OR Y=1346 OR Y=1350 OR Y = 1354 OR
Y=1358 OR Y=1362 OR Y=1366 OR Y=1370 OR Y=1374 OR Y = 1378 OR Y=1382 OR Y=1386
OR Y=1390 OR Y=1394 OR Y=1398 OR Y=1402 Then
If M = 12 and D = 10 Then
Select Case Y
Case 1302
Y = 1924 : M = 2 : D = 29: exit sub
Case 1306
Y = 1928 : M = 2 : D = 29: exit sub
Case 1310
Y = 1932 : M = 2 : D = 29: exit sub
Case 1314
Y = 1936 : M = 2 : D = 29: exit sub
Case 1318
Y = 1940 : M = 2 : D = 29: exit sub
Case 1322
Y = 1944 : M = 2 : D = 29: exit sub
Case 1326
Y = 1948 : M = 2 : D = 29: exit sub
Case 1330
Y = 1952 : M = 2 : D = 29: exit sub
Case 1334
Y = 1956 : M = 2 : D = 29: exit sub
Case 1338
Y = 1960 : M = 2 : D = 29: exit sub
Case 1342
Y = 1964 : M = 2 : D = 29: exit sub
Case 1346
Y = 1968 : M = 2 : D = 29: exit sub
Case 1350
Y = 1972 : M = 2 : D = 29: exit sub
Case 1354
Y = 1976 : M = 2 : D = 29: exit sub
Case 1358
Y = 1980 : M = 2 : D = 29: exit sub
Case 1362
Y = 1984 : M = 2 : D = 29: exit sub
Case 1366
Y = 1988 : M = 2 : D = 29: exit sub
Case 1370
Y = 1992 : M = 2 : D = 29: exit sub
Case 1374
Y = 1996 : M = 2 : D = 29: exit sub
Case 1378
Y = 2000 : M = 2 : D = 29: exit sub
Case 1382
Y = 2004 : M = 2 : D = 29: exit sub
Case 1386
Y = 2008 : M = 2 : D = 29: exit sub
Case 1390
Y = 2012 : M = 2 : D = 29: exit sub
Case 1394
Y = 2016 : M = 2 : D = 29: exit sub
Case 1398
Y = 2020 : M = 2 : D = 29: exit sub
Case 1402
Y = 2024 : M = 2 : D = 29: exit sub
End Select
end if
If M = 12 and D > 10 Then
D = D - 1
End If
elseif Y=1343 OR Y=1347 OR Y=1351 OR Y=1355 OR Y=1359 OR Y=1363 OR Y=1367
OR Y=1371 OR Y=1375 OR Y=1379 OR Y=1383 OR Y=1387 OR Y=1391 OR Y=1395 OR Y=1399
OR Y=1403 then
D = D - 1
if D = 0 then
M = M - 1
if M > 0 and M < 7 then D = 31
if M > 6 then D = 30
if M = 0 then
D = 29
M = 12
Y = Y - 1
end if
end if
End If
'*******************
If M < 10 Or (M = 10 And D < 11) Then
Y = Y + 621
Else
Y = Y + 622
End If
Select Case M
Case 1
If D < 12 Then
M = 3: D = D + 20
Else
M = 4: D = D - 11
End If
Case 2
If D < 11 Then
M = 4: D = D + 20
Else
M = 5: D = D - 10
End If
Case 3
If D < 11 Then
M = 5: D = D + 21
Else
M = 6: D = D - 10
End If
Case 4
If D < 10 Then
M = 6: D = D + 21
Else
M = 7: D = D - 9
End If
Case 5, 6, 8
If D < 10 Then
M = M + 2: D = D + 22
Else
M = M + 3: D = D - 9
End If
Case 7
If D < 9 Then
M = 9: D = D + 22
Else
M = 10: D = D - 8
End If
Case 9
If D < 10 Then
M = 11: D = D + 21
Else
M = 12: D = D - 9
End If
Case 10
If D < 11 Then
M = 12: D = D + 21
Else
M = 1: D = D - 10
End If
Case 11
If D < 12 Then
M = 1: D = D + 20
Else
M = 2: D = D - 11
End If
Case 12
If D < 10 Then
M = 2: D = D + 19
Else
M = 3: D = D - 9
End If
End Select
End Sub
Function ChangeToPersian(DateParam)
M = cInt(Left(DateParam, InStr(DateParam, "/") - 1 ))
D = cInt(Mid(DateParam, InStr(DateParam, "/") + 1, InStrRev(DateParam, "/")
- InStr(DateParam, "/") - 1))
Y = cInt(Mid(DateParam, InStrRev(DateParam, "/") + 1))
If Y = 0 Then Y = 2000
If Y < 1000 Then Y = Y + 1900
Persian Y, M, D
ChangeToPersian = Trim(Y) & "/" & Trim(M) & "/" & Trim(D)
End Function
Sub Persian(Y, M, D)
'******************* Leap year
If Y = 1928 OR Y = 1932 OR Y = 1936 OR Y = 1944 OR Y = 1948 OR Y = 1952 OR
Y = 1956 OR Y = 1960 OR Y = 1964 OR Y = 1968 OR Y = 1972 OR Y = 1976 OR Y =
1980 OR Y = 1984 OR Y = 1988 OR Y = 1992 OR Y = 1996 OR Y = 2000 OR Y=2004 OR
Y=2008 OR Y=2012 OR Y=2016 OR Y= 2020 OR Y=2024 Then
If M > 2 Then
Temp = DateSerial(Y, M, D)
Temp = Temp + 1
Y = Year(Temp)
M = Month(Temp)
D = Day(Temp)
End If
End If
'*******************
If M < 3 Or (M = 3 And D < 21) Then
Y = Y - 622
Else
Y = Y - 621
End If
Select Case M
Case 1
If D < 21 Then
M = 10: D = D + 10
Else
M = 11: D = D - 20
End If
Case 2
If D < 20 Then
M = 11: D = D + 11
Else
M = 12: D = D - 19
End If
Case 3
If D < 21 Then
M = 12: D = D + 9
Else
M = 1: D = D - 20
End If
Case 4
If D < 21 Then
M = 1: D = D + 11
Else
M = 2: D = D - 20
End If
Case 5, 6
If D < 22 Then
M = M - 3: D = D + 10
Else
M = M - 2: D = D - 21
End If
Case 7, 8, 9
If D < 23 Then
M = M - 3: D = D + 9
Else
M = M - 2: D = D - 22
End If
Case 10
If D < 23 Then
M = 7: D = D + 8
Else
M = 8: D = D - 22
End If
Case 11, 12
If D < 22 Then
M = M - 3: D = D + 9
Else
M = M - 2: D = D - 21
End If
End Select
End Sub
%>
<form name="form1" method="post" action="">
<p>
<input name="txtDate" type="text" id="txtDate">
<select name="cboDate" id="cboDate">
<option value="Persian">Persian</option>
<option value="English" selected>English</option>
</select>
<input type="submit" name="Submit" value=">>">
<input name="textfield" type="text" value="<%=strDateConverted%>">
</p>
<ul>
<li>Persian: 1382/2/2 (YYYY/M/D)</li>
<li>English 12/24/2003 (MM/DD/YYYY) </li>
</ul>
</form>
</body>
</html>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four
times a year.
http://www.fusionauthority.com/quarterly
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:253229
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4