+ 1

Convert.DateTime format

Simple question... (c#) DateTime DataNascita = new DateTime(2010, 1, 1); DataNascita = Convert.ToDateTime(Console.ReadLine()); Console.WriteLine(DataNascita); My date is in mm/dd/yyyy hh.mm.ss format. How i can change to dd/mm/yyyy format without hours/minutes/seconds?

25th Nov 2017, 11:20 AM
Marco
Marco - avatar
7 Answers
+ 11
or alternatively, you may write it as:- DataNascita.ToString("dd/MM/yyyy"); Hopefully it helps! 😉
26th Nov 2017, 2:47 AM
Zephyr Koo
Zephyr Koo - avatar
+ 2
resolved with: Console.WriteLine(DataNascita.Day + "/" + DataNascita.Month + "/" + DataNascita.Year); :P
25th Nov 2017, 11:52 AM
Marco
Marco - avatar
+ 1
Convert.ToDateTime(DateTime.ParseExact("dateString","dd/MM/yyyy",CultureInfo.InvariantCulture)); not sure work.
25th Nov 2017, 11:25 AM
Momo Belia
Momo Belia - avatar
+ 1
I have add the "using System.Globalization;" and the compile run but I still see the MM/dd/yyyy hh:mm:ss format... :|
25th Nov 2017, 11:50 AM
Marco
Marco - avatar
0
..\Playground\(28,84): error CS0103: The name 'CultureInfo' does not exist in the current context
25th Nov 2017, 11:47 AM
Marco
Marco - avatar
0
I had only one problem now.... wirh value of one number, like 6, Console.WriteLine(DataNascita.Day give my "6". How i can obtain "06" ?
25th Nov 2017, 1:49 PM
Marco
Marco - avatar
0
resolved with Giorno = Convert.ToString(DataNascita.Day); if(Giorno.Length < 2) { Giorno = "0" + Giorno; }
25th Nov 2017, 2:08 PM
Marco
Marco - avatar