ahmed salah

ahmed salah

  • 1.2k
  • 547
  • 66.1k

input string not in correct format with date and time ?

Nov 8 2023 1:27 AM

I work on asp.net mvc application . i get error when publish application over iis but on local machine not get any error

i search for that i found that error on datetime on the line below

if (Session[SessionKeys.VisaExpiryDate] == null)
{
    visaExpiryDate = 0;
}
else
{
   DateTime visDateExpire = Convert.ToDateTime(Session[SessionKeys.VisaExpiryDate]);
    visaExpiryDate = JulianDate.DateTimeToJulian(visDateExpire);

}

for details as below 

if (Session[SessionKeys.VisaExpiryDate] == null)
{
    visaExpiryDate = 0;
}
else
{
   DateTime visDateExpire = Convert.ToDateTime(Session[SessionKeys.VisaExpiryDate]);
    visaExpiryDate = JulianDate.DateTimeToJulian(visDateExpire);

}

  public static int DateTimeToJulian(DateTime dateTime)
  {
      string szDate = string.Empty;
      int nPrefix = 0;
      int nSufix = 0;

      nPrefix = (Convert.ToInt32(dateTime.Year.ToString().Substring(1, 1) + "00") + 100) + Convert.ToInt32(dateTime.Year.ToString().Substring(2, 2));

      nSufix = dateTime.DayOfYear;
      szDate = nPrefix.ToString() + nSufix.ToString("000");

      if (szDate.Length > 6)
          szDate = szDate.Substring(1, 6);

      return Convert.ToInt32(szDate);
  }

errror say input string not in correct formate with datetime 

so How to solve this error to work on server ?


Answers (5)