.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

problem in datetime and gridview

Posted By: Shweta     Posted Date: August 03, 2010    Points:2   Category :ASP.Net

In sql server in date is stored in a particular format. so if i want to display only date or only time in the GridView there any solution?


Author: Mallikarjuna Chigicherla             
Posted Date: August 03, 2010     Points: 5   

Hi, Try with this code:
You can do this by setting html encode property is equal to false.

and data format strings like

For just date only ={0:d} 11/16/2009

For just date only ={0:D} Tuesday, June 23, 2009

For just date only ={0:T} 12:00:00

<asp:BoundField DataField="Date" HeaderText="Date Of Birth" HtmlEncode="False" DataFormatString = "{0:d}" ReadOnly="True" />

For Long Date,
<asp:BoundField DataField="Date" HtmlEncode="False" DataFormatString = "{0:D}" HeaderText="Date Of Birth[Long Date]" ReadOnly="True" />

For Long Time,

<asp:BoundField DataField="Date" HtmlEncode="False" DataFormatString = "{0:T}" HeaderText="Date Of Birth[Long Time]" ReadOnly="True" />

Thanks & Regards,
Mallikarjuna Chigicherla
Author: swathi             
Posted Date: August 11, 2010     Points: 5   

if you want to get only date try this..

select convert(varchar(12),datecolumnname,103) from tablename


Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend