Reputation: 1626
All I want to do is to get the date on the SQL database for only the month and day and bind it into repeater:
FRONT:
<asp:Repeater ID="rep_content" runat="server">
<ItemTemplate>
<div class="date">
<p><%# Eval("BLG_DATE") %> of <span><%#Eval("BLG_DATE") %></span>
</div>
</ItemTemplate>
</repeater>
BACK:
daString = "SELECT * FROM [BLG] INNER JOIN [ACC] ON [BLG].ACC_ID=[ACC].ACC_ID WHERE [BLG].ACC_ID='" + userID + "'";
SqlDataAdapter da = new SqlDataAdapter(daString, conn);
DataTable dt = new DataTable();
da.Fill(dt);
rep_content.DataSource = dt;
rep_content.DataBind();
BLG Table:
BLG_ID,ACC_ID,BLG_TITLE,BLG_DES,BLG_DATE,BLG_IMG
Output should be:
23 of JAN
Upvotes: 0
Views: 878
Reputation: 3864
Do like this,
<asp:Repeater ID="rep_content" runat="server">
<ItemTemplate>
<div class="date">
<p><%# Eval("DDay") %> of <span><%#System.Globalization.DateTimeFormatInfo.InvariantInfo.GetAbbreviatedMonthName(Convert.ToInt32(Eval("DMonth")))%></span>
</div>
</ItemTemplate>
</repeater>
Upvotes: 0
Reputation: 15387
Use DatePart
to get day and month
daString = "SELECT datepart (dd, BLG_DATE) as DDay,datepart (mm, BLG_DATE) as DMonth
FROM [BLG] INNER JOIN [ACC] ON [BLG].ACC_ID=[ACC].ACC_ID
WHERE [BLG].ACC_ID='" + userID + "'";
SqlDataAdapter da = new SqlDataAdapter(daString, conn);
DataTable dt = new DataTable();
da.Fill(dt);
rep_content.DataSource = dt;
rep_content.DataBind();
<p><%# Eval("DDay") %> of <span><%#Eval("DMonth") %></span>
Upvotes: 1