Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need customize date format in asp.net c#.

example 1:

VB
My Date : "15/10/2012 15:13:10"
Format: YYYYMMDDHHMMSS
Ex: dateTime=20121015151310


example 2:

VB
My Date : "23/10/1975"
Format: YYYYMMDD
Ex: birthDate=19751023


below code not working:

VB
string sDate = DateTime.Now.ToString("YYYYMMDDHHMMSS");
Posted

Try this:
C#
string sDate = DateTime.Now.ToString("yyyyMMddHHmmss");


http://msdn.microsoft.com/en-us/library/vstudio/8kb3ddd4%28v=vs.100%29.aspx[^]

Cheers!
 
Share this answer
 
v2
Try

DateTime.Now.ToString("yyyyMMddHHmmss");

Please refer Formats for DateTime.ToString()[^]
 
Share this answer
 
Your code'll not display any error but the Problem is YYYY and SS is not the valid Date time Formatting string so it'll not give you the actual result.

you have to use yyyy instead of YYYY and ss instead of SS.

See here
http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx[^]
 
Share this answer
 

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