Try this method:
public static string ConvertDateString(string DATE_INS, int COND)
{
string functionReturnValue = null;
int CurrentDay;
int CurrentMonth;
int CurrentYear;
System.DateTime DateFrom;
DateFrom = Strings.Trim(DATE_INS);
CurrentDay = DateFrom.Day;
CurrentMonth = DateFrom.Month;
CurrentYear = DateFrom.Year;
if (COND == 1)
{
// من هجرى الى ميلادى
System.DateTime ConversionDate = new System.DateTime(CurrentYear, CurrentMonth, CurrentDay, new HijriCalendar());
functionReturnValue = ConversionDate;
}
else if (COND == 2)
{
CultureInfo higri_format = new CultureInfo("ar-SA"); higri_format.DateTimeFormat.Calendar = new HijriCalendar();
System.DateTime CurrentDate;
if (!Information.IsDate(DATE_INS))
{
functionReturnValue = "";
return;
// TODO: might not be correct. Was : Exit Function
}
CurrentDate = Convert.ToDateTime(DATE_INS);
functionReturnValue = CurrentDate.Date.ToString("dd/MM/yyyy", higri_format);
}
return functionReturnValue;
}
Good Luck
Friday, July 25, 2008
Subscribe to:
Post Comments (Atom)


4 comments:
The code needs some clarification, test the code again and see.. for example what is DATE_INS? is it the date needed to be converted? and what is the format? the return hijri date is for Im alqura calendar?
Dear mohnod
this code work 100% and i use it to convert date to Hijri date
please try this code again
public static string ConvertDateString(string DATE_INS, Int32 COND)
{
string ConvertDateString = "";
Int32 CurrentDay;
Int32 CurrentMonth;
Int32 CurrentYear;
DateTime DateFrom;
//
DateFrom = Convert.ToDateTime(DATE_INS.Trim());
CurrentDay = DateFrom.Day;
CurrentMonth = DateFrom.Month;
CurrentYear = DateFrom.Year;
if (COND == 1)//من هجرى الى ميلادى
{
DateTime ConversionDate;
ConversionDate = new DateTime(CurrentYear, CurrentMonth, CurrentDay, new HijriCalendar());
ConvertDateString = ConversionDate.ToString();
}
else if (COND == 2) // من ميلادى الى هجرى
{
CultureInfo higri_format = new CultureInfo("ar-SA");
higri_format.DateTimeFormat.Calendar = new HijriCalendar();
DateTime CurrentDate;
DateTime x;
if (!DateTime.TryParse(DATE_INS, out x))
{
ConvertDateString = "";
return "";
}
CurrentDate = Convert.ToDateTime(DATE_INS);
ConvertDateString = CurrentDate.Date.ToString("dd/MM/yyyy", higri_format);
}
return ConvertDateString;
}
But according to your question about DATE_INS is your date that you want to convert to Hijri date
for example :
string datetime = calender1.SelectedDate.ToString("MM/dd/yyyy");
so your hijri date will be
string Hijri = Helper.ConvertDateString(calender1.SelectedDate.ToShortDateString(), 2);
Good Luck
and hope it helps you
thanks I used a part of it and was fine :)
Post a Comment