Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Dear Frnds,

I have table with Users,
I have binded and displayed in GRIDVIEW.

In that i have Fields like Issue date and Expiry Date.
it is displaying date and time like this 4/29/2012 12:00:00 AM
Just i need to display only date not time
I want to display like this in gridview 29/4/2012

Please suggest me. how to do this ?

Thanks,
Posted
Updated 27-Mar-22 20:24pm
Comments
Sandeep Mewara 13-May-12 5:19am    
You don't Google at all? Haven't read any documentation or book? Right! Don't like them.?

You can use the ToString() method with a mask:
C#
ToString("MM/dd/yyyy");


OR you can use
C#
.ToShortDateString();


OR if you are using boundfield then try following:
C#
<asp:BoundField HeaderText="Date" DataField="MyDate" 
     DataFormatString="{0:MM/dd/yy}">


OR try following:
Setting DataColumn to just a Date not a Datetime
 
Share this answer
 
v2
Comments
bbirajdar 13-May-12 6:54am    
correct solution
Monjurul Habib 13-May-12 6:58am    
did you down vote me accidentally!!
bbirajdar 13-May-12 11:49am    
Oh..Is that? I will vote 5 (again)...Your solution is correct in every sense
Monjurul Habib 13-May-12 15:25pm    
thanks :)
Sandeep Mewara 13-May-12 9:23am    
My 5!
You can use string.Format() method while displaying data :-

GRIDVIEW.Rows[rowNum].Cells[colName].Value = string.Format("{0:dd/MM/yyyy}",29/04/2012 12:00:00 AM);

Hope this work :)
 
Share this answer
 
Comments
sheida1367 13-Aug-12 9:15am    
hi
how can dont show time in gridview when print it?
thanks
C#
DataGridViewTextBoxColumn dateOfBirth = new DataGridViewTextBoxColumn();
dateOfBirth.DefaultCellStyle.Format = "MM/dd/yyyy";
 
Share this answer
 
v2
Hi
Right Click ON Dgv And Go To Edit Ciolumns And Go To Column You Want To View Date On it Then At Appearance Go To DefaultCellStyle Ant Set Format To MM/dd/yyyy
I Hope That Help You
 
Share this answer
 
Use GETDATE() but it display both current date and time so what you need to do
take date as datattype
For Eg:

create table employee(
id int identity (1,1),
Name varchar(50), Mobile Bigint NOT NULL PRIMARY KEY,
Salary bigint, Status int default(1), Date date NOT NULL DEFAULT CAST( GETDATE() AS Date ) );
or
create table employee(
id int identity (1,1),
Name varchar(50), Mobile Bigint NOT NULL PRIMARY KEY,
Salary bigint, Status int default(1), Date date NOT NULL DEFAULT GETDATE() );

BOTH WILL WORK

REGARDS
TANMAY RAI
 
Share this answer
 
Comments
CHill60 28-Mar-22 3:49am    
Reason for my downvote - you have not solved any issues about display in GridView and there was no mention of the need for a default. In addition you are using a reserved word for a column name without surrounding it in brackets i.e. [Date]. The question also already has 5 more accurate answers.
Stick to new questions unless you are bringing something really new to the thread - but make sure you are both accurate and relevant - this is neither.

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