Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert datetime to date format dd/mm/yyyy

Tags:

c#

.net

I have a DateTime object 2/19/2011 12:00:00 AM. I want to convert this object to a string 19/2/2011.

Please help me to convert DateTime to string format.

like image 510
Aswathi Avatar asked Feb 19 '11 10:02

Aswathi


People also ask

How do I convert DateTime to date format?

To convert a datetime to a date, you can use the CONVERT() , TRY_CONVERT() , or CAST() function.

How do you convert DateTime to mm dd yyyy?

string date = DateTime. ParseExact(SourceDate, "dd/MM/yyyy", CultureInfo. InvariantCulture). ToString("yyyy-MM-dd");


2 Answers

DateTime dt = DateTime.ParseExact(yourObject.ToString(), "MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);  string s = dt.ToString("dd/M/yyyy", CultureInfo.InvariantCulture); 
like image 161
Karel Avatar answered Oct 04 '22 09:10

Karel


First of all, you don't convert a DateTime object to some format, you display it in some format.

Given an instance of a DateTime object, you can get a formatted string in that way like this:

DateTime date = new DateTime(2011, 2, 19); string formatted = date.ToString("dd/M/yyyy"); 
like image 37
Jeff Mercado Avatar answered Oct 04 '22 09:10

Jeff Mercado