datetime in gridview in this format in asp.net

Posted by Dn2010 under ASP.NET on 4/4/2012 | Points: 10 | Views : 1966 | Status : [Member] | Replies : 2
hi friends,


now display datetime in gridview in this format

4/3/2012 10:44:42 PM


But i want to show datetime like this below in gridview

2012-04-03 22:44:42.000


how to convert calldate in selct query

string CommandText = "SELECT calldate,userfield FROM data WHERE calldate BETWEEN '" + last_datetime + "' AND CURDATE() Order By calldate desc limit 20";





DateTime last_datetime = Convert.ToDateTime(Label1.Text);

//DateTime last_datetime = DateTime.ParseExact(Label1.Text, "0:yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);




string ConnectionString = @"driver={MySQL ODBC 3.51 Driver};server=" + ServerName + ";database=" + databasename + ";uid=" + UserName + "; pwd= " + password + "; ";

string CommandText = "SELECT calldate,userfield FROM data WHERE calldate BETWEEN '" + last_datetime + "' AND CURDATE() Order By calldate desc limit 20";






please give the solution,

thanks.




Responses

Posted by: Jayakumars on: 9/29/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
Dn2010
try this code

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false"
BorderColor="#336699" BorderStyle="Solid" BorderWidth="2px"
CellPadding="4" DataKeyNames="ID"
ForeColor="#333333">

<Columns>

<asp:BoundField DataField="ID" HeaderText="ID"
SortExpression="ID" />

<asp:ButtonField ButtonType="link" CommandName="Column_Name"
DataTextField="Column_Name" HeaderText="Column_Name"
SortExpression="Column_Name" />

<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbl1" runat="server" Text ='<%# Bind("Date","{0:d}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

</Columns>

</asp:GridView>



Mark as Answer if its helpful to you

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/29/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

Please mark as answer if it helpful to you.

Mark as Answer if its helpful to you

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response