I have this date field '20171130' saved in the database, and I need to convert to string formatting "30/11/2017" in my application, how to do this type of conversion? .
I have this date field '20171130' saved in the database, and I need to convert to string formatting "30/11/2017" in my application, how to do this type of conversion? .
You can use DateTime.TryParseExact
to convert to < in> string on an instance of DateTime
and then do any formatting.
var strDate = "20171130"; // Este é o valor recuperado do banco
DateTime dateValue;
DateTime.TryParseExact(strDate, "yyyyMMdd", CultureInfo.InvariantCulture,
DateTimeStyles.None, out dateValue);
Console.WriteLine(dateValue.ToString("dd/MM/yyyy"));
No need to convert. If you are fetching the data from a database, it is already picked up by select. Example:
SELECT *,date_format('data','%d/%m/%Y') as 'data_formatada' FROM tabela
So it takes all the data from the table and the new date will be named data_format.