Click here to Skip to main content
15,850,298 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi, I have the following codes, how can I display the date in a format of "2014-12-31"?
I have tried below but it gives me error red line below of my codes.

C#
dto = new LabelPrintDataDto();
dto.Key = "$DateTime$";
dto.Value = unitdto.ManufactureDate.ToString("yyyy MM dd");
labelPrintDataListDto.DtoList.Add(dto);
Posted
Comments
Abhinav S 30-Dec-14 21:58pm    
What is dto.Value type?
Agent__007 30-Dec-14 22:04pm    
Can you elaborate "the red line"? What error the compiler is giving when you build the project?

You must use "yyyy-MM-dd" for me below code is working fine as you expected:
C#
DateTime dt = DateTime.Now;
string formatedDate = dt.ToString("yyyy-MM-dd");

And for more have a look on below link with many sample code snippets:
http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx[^]

Thanks.
 
Share this answer
 
v3
Comments
PIEBALDconsult 30-Dec-14 22:00pm    
mm is minutes, no?
Snesh Prajapati 30-Dec-14 22:05pm    
I just update to MM...and verified in a console app. I updated the answer too. Hope it will help you.
Jamie888 1-Jan-15 20:16pm    
Thanks sir, it helps me a lot.
Snesh Prajapati 1-Jan-15 22:00pm    
Most welcome. :-)
You should use DateTime.TryParseExact Method[^].
 
Share this answer
 
Comments
Jamie888 1-Jan-15 20:16pm    
Thanks sir, it helps me a lot.
Hi,

Follow this link for any kind of date and time formatting.
Date and time format with examples

Thanks
Sisir Patro
 
Share this answer
 
Comments
Jamie888 1-Jan-15 20:16pm    
Thanks sir, it helps me a lot.
[no name] 2-Jan-15 0:01am    
Welcome...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900