Click here to Skip to main content
15,915,975 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
'{2012/12/19 11:59:59 PM}' //So the date looks like this


I need the date to be selected to the following format {yymmdd}

so initially that date needs to be converted to look like 121219

then needs to be converted to a string.
Posted

You can do it by String.Format()
C#
// create date time 
DateTime dt = new DateTime();
String.Format("{0:yyMMdd}", dt); 

For more options please visit this link[^].

Good luck,
OI
 
Share this answer
 
The System.DateTime[^] structure provides methods to parse strings (TryParse()[^]) and to format itself into a string (ToString()[^]).
Combine them to get what you need.
 
Share this answer
 
So you need the datetime in format yyMMdd.
Using the following code
C#
DateTime thisDate1 = DateTime.Now;//Just getting set to the current date and time 
Console.WriteLine("Formated Date is: " + thisDate1.ToString("yyMMdd") + ".");
 
Share this answer
 
you can use code like
C#
DateTime dt = DateTime.Now;
string str = dt.ToString("yymmdd");
 
Share this answer
 
v2
Comments
Orcun Iyigun 4-Dec-12 8:04am    
mm => for minutes MM => for month...

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