-1

In Visual Studio ASP.NET

Code:

<asp:sqldatasource id="sqldatasource3" 
                   runat="server" 
                   connectionstring="<%$ ConnectionStrings:VPSConnectionString %>" 
                   selectcommand="SELECT [Price], [Date], [Route_Start], [Route_Destination] FROM [Billing] WHERE ([Username] = @Username)">
  <SelectParameters>
    <asp:SessionParameter Name="Username" 
                          SessionField="username_universal" 
                          Type="String" />
  </SelectParameters>
</asp:sqldatasource>

Database:

enter image description here

Im trying to filter the entries on the webpage based on the date to the current date. I have successfully filtered by the username but I can't seem to figure out how to use the current date within this .aspx file.

Any help is greatly appreciated.

Lews Therin
  • 3,707
  • 2
  • 27
  • 53

1 Answers1

1

If it's just the current date, you could use the SQL GETDATE() function. In order to match date only, you'll need to either do a CAST(GETDATE() AS DATE) or FLOOR(CAST(GETDATE() AS FLOAT)) in your query to properly match.

Example:

SELECT [Price]
,   [Date]
,   [Route_Start]
,   [Route_Destination] 
    FROM [Billing] 
    WHERE [Username] = @Username 
      AND CAST(GETDATE() AS DATE) = CAST([Date] AS DATE)

See also: Compare DATETIME and DATE ignoring time portion

Alan Samet
  • 1,118
  • 2
  • 15
  • 18