Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
Can any one help me how to remove the time 02-02-2012 00:00:00 which is in label using asp.net.

Thanks in Advance.
Posted
Updated 2-Feb-12 3:15am
Comments
Rajesh Anuhya 2-Feb-12 9:15am    
Edited: "Treat my content as plain text, not as HTML" disabled.
--RA

Go through the below links for different date formats

http://www.csharp-examples.net/string-format-datetime/[^]
http://www.dotnetperls.com/datetime-format[^]

Thanks
--RA
 
Share this answer
 
Comments
Shanthoshshanmugam 2-Feb-12 9:51am    
Thanks!!!

I got it!!
You shouldn't 'remove', you should instead 'properly format' (see "Standard Date and Time Format Strings"[^]):
C#
myLabel.Text = myDate.ToString("d");
 
Share this answer
 
Comments
Shanthoshshanmugam 2-Feb-12 9:38am    
Am using the below format getting the row from grid and showing it in label

lblsecdresolvedDate.Text = table.Rows[0]["ResolvedDate"].ToString();

but this (myLabel.Text = myDate.ToString("d");) format is not working.
Shanthoshshanmugam 2-Feb-12 9:52am    
Thanks!!!

I got it!!
Just add this to the code
(let say you want today's date in the Label)

DateTime dtm = DateTime.Now;

Label_Id.text= dtm.ToString("dd/MM/yyyy");


Hope it help.

Thanks!!
 
Share this answer
 
v2
Comments
Shanthoshshanmugam 2-Feb-12 9:38am    
Am using the below format getting the row from grid and showing it in label

lblsecdresolvedDate.Text = table.Rows[0]["ResolvedDate"].ToString();

but this (Label_Id.text= dtm.ToString("dd/MM/yyyy");) format is not working.
vjdeeds 2-Feb-12 9:46am    
This should work then,

DateTime dtm = Convert.ToDateTime(table.Rows[0]["ResolvedDate"].ToString());

lblsecdresolvedDate.Text = dtm.ToString("dd/MM/yyyy");
or
lblsecdresolvedDate.Text = dtm.ToShortDateString();
Shanthoshshanmugam 2-Feb-12 9:51am    
Thanks!!!

Its working Properly!!!
DateTime dtm = DateTime.Parse("02-02-2012 00:00:00");
this.lblOutput.Text = dtm.ToShortDateString();
 
Share this answer
 
Comments
Shanthoshshanmugam 2-Feb-12 9:52am    
Thanks!!!

I got it!!
Hi,

I just want to add another simple way to display data with specified format using Eval and Bind...
If your label is bound to some data source you can format display through markup.

Example:
ASP.NET
<asp:label id="Label1" runat="server" text="<%# Eval("DateTimeDataFieldName", "yyyy-MM-dd")%>" xmlns:asp="#unknown"></asp:label>


Eval method is defined as:
C#
protected internal string Eval(
string expression,
string format
)
so you can use any other format string. For all format strings definition refer to documentation [^].
 
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