Home > ASP.Net > Method to convert Date to Hijri

Method to convert Date to Hijri


Try this example:

The date should be in format MM/dd/yyyy

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

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: