tags:

views:

33

answers:

2

hi

i need convert date to shamsi date

i create a method that convert DateTime to shamsi Date.

when i passing a date to the method i got this error

The best overloaded method match for 'BentaAccounting.Classes.GenralClasses.FarsiDate.MiladiToShamsi(System.DateTime)' has some invalid arguments

this is the code i am using

the method

public static string MiladiToShamsi(DateTime Date)   
      {   
           string Result;   
           PersianCalendar FarsiDate = new PersianCalendar();   
            Result = FarsiDate.GetYear(Date).ToString() + "/" +   
                (FarsiDate.GetMonth(Date) < 10 ? "0" + FarsiDate.GetMonth(Date).ToString() : FarsiDate.GetMonth(Date).ToString()) + "/" +   
                (FarsiDate.GetDayOfMonth(Date) < 10 ? "0" + FarsiDate.GetDayOfMonth(Date).ToString() : FarsiDate.GetDayOfMonth(Date).ToString());   
            return Result;   
        }  

and view

<%: Html.Encode(GenralClasses.FarsiDate.MiladiToShamsi(item.OrderDate) )%> 
A: 

Try This

public static string MiladiToShamsi(DateTime Date)   
      {   
           string Result;   
           string Year;
           string Month;
           string Day;
           # string Result, Year, Month, Day I don't know this works or not in asp.net 
           PersianCalendar FarsiDate = new PersianCalendar();   
            Year = FarsiDate.GetYear(Date).ToString();
            Month = (FarsiDate.GetMonth(Date) < 10 ? "0" + FarsiDate.GetMonth(Date).ToString() : FarsiDate.GetMonth(Date).ToString());
            Day = (FarsiDate.GetDayOfMonth(Date) < 10 ? "0" + FarsiDate.GetDayOfMonth(Date).ToString() : FarsiDate.GetDayOfMonth(Date).ToString());
            Result = Year + "/" +   Month   + "/" +   Day  ;   
            return Result;   
        }  
Salil
A: 

The only reason you get this exception is - item.OrderDate's type not a DateTime. Maby it's string or something else.

er-v
NO i am sure that data type of orderDate is DateTime
Ali
This is very strange. I tryed your code in the following way and it works just fine <%: Html.Encode(GenralClasses.FarsiDate.MiladiToShamsi(DateTime.Now) )%> Does it works for you?
er-v
No it doesn't works for me.the data type of OrderDate was nvarchar before and i changed it to datetime.
Ali