2
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 ?.
2
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 ?.
4
It is possible to use DateTime.TryParseExact
to convert the string in 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"));
Remove the new from Cultureinfo.Invariantculture, because it is static... the way it is not working...
@samuelrvg had left the old code. Obg
0
You don’t have to convert. If you are taking the data from a database, it already gets converted 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 with the data_formatted name.
Blz, but in this case how would select ? use Entity Framework
I think sql is the same in all languages, because you will directly manipulate the database. So just adapt this query to your C code#.
Browser other questions tagged c# asp.net-mvc database
You are not signed in. Login or sign up in order to post.
At what point do you want to do this conversion, young man? In the bank or in the application?
– Jéf Bueno
Good, I’ll edit to specify. @LINQ
– Samuel Renan Gonçalves Vaz
because Voce did not save in the bank so "30/11/2017"?
– Julio Henrique
Why do I get a json in this format and already saved directly in the bank. @Juliohenrique97
– Samuel Renan Gonçalves Vaz