Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to display date in dd/mm/yyyy format

I have a label with name lbldate

so iam writing my code as lbldate.Text=System.DateTime.Now.ToShortDateString();
it is displaying as 1/15/2013.

But,

I need it as 15/1/2013 (day month year) Format.

Please give me a good Solution. Thanks in Advance.
Posted

If you use a standard format, the result depends on the culture that is set for the machine executing the code (which I suspect will be the Server in your case, not the Client). If you want a specific data format, then you need to specify exactly what you want:
C#
lbldate.Text=System.DateTime.Now.ToString("dd/MM/yyyy"); 
And the Culture will be ignored.

There is a list of the format strings here: Formatting a DateTime for display - format string description[^]
 
Share this answer
 
Comments
Ranjith Reddy CSE 15-Jan-13 2:56am    
Thanks...............
OriginalGriff 15-Jan-13 3:01am    
You're welcome!
Member 11993344 18-Sep-15 12:37pm    
x
__TR__ 15-Jan-13 2:57am    
+5
For example, System.DateTime.Now.ToString("dd/mm/yyyy"); please see:
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx[^],
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^].

You can also use the particular culture with this date format:
http://msdn.microsoft.com/en-us/library/ht77y576.aspx[^].

—SA
 
Share this answer
 
Comments
__TR__ 15-Jan-13 2:55am    
+5
Sergey Alexandrovich Kryukov 15-Jan-13 3:09am    
Thank you.
—SA
Ranjith Reddy CSE 15-Jan-13 2:56am    
Thanks...............
Sergey Alexandrovich Kryukov 15-Jan-13 3:09am    
You are welcome.
—SA
Try
C#
lbldate.Text = DateTime.Now.ToString("dd/MM/yyyy");
 
Share this answer
 
Comments
Ranjith Reddy CSE 15-Jan-13 2:56am    
Thanks...............
__TR__ 15-Jan-13 6:36am    
You are welcome.
Hello

You Can use
System.DateTime.Now.ToShortDateString();

it gives your system Short Date time thats why it would give you.
1/15/2013
if you change your System or server time setting than it will give you write Time As you Want and either case you can simple use
lbldate.Text = DateTime.Now.ToString("dd/MM/yyyy");
 
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