[Solved] Date format working locally error after publishing on IIS

on Jul 21, 2021 06:06 AM

Hi Guys,

I'm get trouble when project finished and publish on IIS server. The trouble is Date Format can change itself after it is run on IIS Server. - Format Date in Database is 2021-09-05 (yyyy-MM-dd) (year-month-date)

After project publish on IIS server the Date Format is - Format Date in IIS Server is (09-05-2021) (MM-dd-yyyy)(month-date-year). This is invalid date format in Indonesian.

I have try to format that date format using string.format() in code behind.cs like this below.

txttgl_jatuh_tempo.Text = string.Format("{0:dd-MM-yyyy}", rdr["tanggal_jatuh_tempo"].ToString()); 

The code above is working properly when deployed on visual studio and get correct result of date format, but after project completed and deployed/running on IIS server the date format was change itself with this date format (09-05-2021) (MM-dd-yyyy)(month-date-year).

Of course this this date format make user confused because correct Indonesian date format is (date-month-years) (dd-MM-yyyy).

Any help could be appriciate.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Jul 21, 2021 06:24 AM
on Jul 21, 2021 06:51 AM

Hi trisetia302,

Use below code to format.

string tanggal_jatuh_tempo = rdr["tanggal_jatuh_tempo"].ToString();
txttgl_jatuh_tempo.Text = DateTime.ParseExact(tanggal_jatuh_tempo, 
                          new string[] { "yyyy-MM-dd", "MM-dd-yyyy", "dd-MM-yyyy", "yyyy-dd-MM" }, 


on Jul 21, 2021 06:40 AM



Alhamdulilah, Problem Solved Sir.

Thanks so much for the help.

This code working properly sir.

DateTime tglJatuhTempo = Convert.ToDateTime(rdr["tanggal_jatuh_tempo"].ToString());
txttgl_jatuh_tempo.Text = string.Format("{0:dd/MM/yyyy}", tglJatuhTempo);