2

i want to create the textbox in asp.net to get the Persian date from user and convert to Georgian date to compare with the date of my date column in my sql database,can anyone help me??

Calum
  • 1,889
  • 2
  • 18
  • 36
m.bahman
  • 19
  • 1
  • 4
  • 1
    You need to post some code to show what you're having problems with. Stack Overflow can help you with specific problems with your code, but your question is too broad. – Martyn Shutt Sep 20 '15 at 11:03
  • 2
    Have a look at this question: "[*How to convert Persian Calendar date string to DateTime?*](http://stackoverflow.com/q/10655116/1364007)" for some tips. n.b. I found it by searching for "c# Persian calendar" in Google - it was the second result for me. – Wai Ha Lee Sep 20 '15 at 16:45
  • Noda Time is helpful here. See [my answer](http://stackoverflow.com/a/32683586/634824) in the duplicate post. – Matt Johnson-Pint Sep 20 '15 at 19:48

1 Answers1

0

you can use this javaScript code:

function jalali_to_gregorian(jy,jm,jd){
 if(jy > 979){
  gy=1600;
  jy-=979;
 }else{
  gy=621;
 }
 days=(365*jy) +((parseInt(jy/33))*8) +(parseInt(((jy%33)+3)/4)) +78 +jd +((jm<7)?(jm-1)*31:((jm-7)*30)+186);
 gy+=400*(parseInt(days/146097));
 days%=146097;
 if(days > 36524){
  gy+=100*(parseInt(--days/36524));
  days%=36524;
  if(days >= 365)days++;
 }
 gy+=4*(parseInt(days/1461));
 days%=1461;
 if(days > 365){
  gy+=parseInt((days-1)/365);
  days=(days-1)%365;
 }
 gd=days+1;
 sal_a=[0,31,((gy%4==0 && gy%100!=0) || (gy%400==0))?29:28,31,30,31,30,31,31,30,31,30,31];
 for(gm=0;gm<13;gm++){
  v=sal_a[gm];
  if(gd <= v)break;
  gd-=v;
 }
 return [gy,gm,gd]; 
}

or use this VisualBasic code:

Function jalali_to_gregorian(ByVal jy As Long, ByVal jm As Long, ByVal jd As Long)

 Dim sal_a(12), out(2), gy, gm, gd, days, jm2, gm2, i As Long

 If jy > 979 Then
  gy = 1600
  jy = jy - 979
 Else
  gy = 621
 End If

 jm2 = IIf(jm < 7, (jm - 1) * 31, ((jm - 7) * 30) + 186)
 days = (365 * jy) + ((jy \ 33) * 8) + (((jy Mod 33) + 3) \ 4) + 78 + jd + jm2
 gy = gy + (400 * (days \ 146097))
 days = days Mod 146097
 If days > 36524 Then
  days = days - 1
  gy = gy + (100 * (days \ 36524))
  days = days Mod 36524
  If days >= 365 Then
   days = days + 1
  End If
 End If
 gy = gy + (4 * (days \ 1461))
 days = days Mod 1461
 If days > 365 Then
   gy = gy + ((days - 1) \ 365)
   days = (days - 1) Mod 365
 End If

source: https://jdf.scr.ir/