Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert DateTime Format

net 4 and c#.

I have in a Text Box DateTimeValue

3/1/2011 12:00:00 AM

I need to convert it in a String of this format:

Format="yyyy-MM-dd"

Any idea how to do it? PS: I can remove information about the time

Thanks for your time

like image 830
GibboK Avatar asked Mar 01 '11 08:03

GibboK


2 Answers

Use DateTime.ParseExact like so:

DateTime.ParseExact("3/1/2011 12:00:00 AM", "G", 
           CultureInfo.GetCultureInfo("en-US")).ToString("yyyy-MM-dd");

Be sure to specify the culture, because the format you used is ambiguous.

like image 144
Daniel Hilgarth Avatar answered Sep 24 '22 06:09

Daniel Hilgarth


is this what are you asking for?

DateTime.Parse("3/1/2011 12:00:00 AM").ToString("yyyy-MM-dd")
like image 33
Rami Alshareef Avatar answered Sep 20 '22 06:09

Rami Alshareef