Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET DateTime
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 14-Jan-13 21:48pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
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[^]
  Permalink  
Comments
Ranjith Reddy CSE at 15-Jan-13 2:56am
   
Thanks...............
OriginalGriff at 15-Jan-13 3:01am
   
You're welcome!
__TR__ at 15-Jan-13 2:57am
   
+5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
__TR__ at 15-Jan-13 2:55am
   
+5
Sergey Alexandrovich Kryukov at 15-Jan-13 3:09am
   
Thank you.
—SA
Ranjith Reddy CSE at 15-Jan-13 2:56am
   
Thanks...............
Sergey Alexandrovich Kryukov at 15-Jan-13 3:09am
   
You are welcome.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try
 lbldate.Text = DateTime.Now.ToString("dd/MM/yyyy");
  Permalink  
Comments
Ranjith Reddy CSE at 15-Jan-13 2:56am
   
Thanks...............
__TR__ at 15-Jan-13 6:36am
   
You are welcome.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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");
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 195
1 Afzaal Ahmad Zeeshan 132
2 ProgramFOX 130
3 Maciej Los 115
4 Sergey Alexandrovich Kryukov 75
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 15 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100