Getting the number of rows for todays date in MS SQL
Great in this example I am going to show you how you can get the rows from sql table (lets say you want to get the number of records that your users had made). For this purpose I will call our sql table just "table" and will make a field called "PostDate" where I am going to store DateTime.Now when user makes a post and I will use this field to compare it with the T-SQL getdate() which returns SQL servers date time. Ok, The "104" argument that you can see is German date time format dd.mm.yyyy.
SELECT COUNT(*) AS [rowcounttoday] FROM table CONVERT(char,PostDate,104) = CONVERT(char,getdate(),104)
Ok let's make a use of this and bind it to a lable control for exapmle:
<asp:SqlDataSource ID="SqldataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnection %>" SelectCommand="Select Count(*) As [rowcounttoday] from posts where convert(char, PostDate, 104) = convert(char, getdate(),104)" />
<asp:DataList ID="datalist1" runat="server" DataSourceID="SqldataSource1">
<ItemTemplate>
<asp:Lable ID="lblTodaysPosts" runat="server" Text="Number of todays posts: " />
<asp:Lable ID="lblNumber" runat="server" Text='<%# Bind ("rowcounttoday")%>' />
</ItemTemplate>
</DataList>
Hope it helps
Cheers