Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. DataView Date FIltering Problem

DataView Date FIltering Problem

Scheduled Pinned Locked Moved ASP.NET
help
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    asifmaniar
    wrote on last edited by
    #1

    Hi, I am trying to filter data from a dataview based on a date column. The problem is that I need to be able to compare just the day and month part of the date. I can't seem to figure it out. Code: I tried both the following filters but convert, ctype etc are unrecognized in the dataview. Any suggestions will be appreciated. Dim filter As String = "ListingID = '{0}' And convert.ToDateTime(StartDate).Day = '{1}' And convert.ToDateTime(StartDate).Month = '{2}'" view.RowFilter = String.Format(filter, ListingID, StartDate.Day, StartDate.Month) OR Dim filter As String = "ListingID = '{0}' And " & CType(view.Table.Columns("StartDate").ToString, DateTime).Day() & " = '" & StartDate.Day & "'"

    M 1 Reply Last reply
    0
    • A asifmaniar

      Hi, I am trying to filter data from a dataview based on a date column. The problem is that I need to be able to compare just the day and month part of the date. I can't seem to figure it out. Code: I tried both the following filters but convert, ctype etc are unrecognized in the dataview. Any suggestions will be appreciated. Dim filter As String = "ListingID = '{0}' And convert.ToDateTime(StartDate).Day = '{1}' And convert.ToDateTime(StartDate).Month = '{2}'" view.RowFilter = String.Format(filter, ListingID, StartDate.Day, StartDate.Month) OR Dim filter As String = "ListingID = '{0}' And " & CType(view.Table.Columns("StartDate").ToString, DateTime).Day() & " = '" & StartDate.Day & "'"

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      Hi there. The expressions available for the DataView.RowFilter property are explained in the documentation for DataColumn.Expression[^]. It's pretty limited. There aren't any date-specific functions I'm aware of, and you can only use CONVERT on a DateTime to change the type to a String. But with that, I'm thinking you may be able to use a combination of CONVERT and SUBSTRING to accomplish what you want. Maybe something like this (untested):

      Dim filter As String = "ListingID = '{0}' And " _
      & "Substring(Convert(StartDate, System.String), 1, 5) = '{1}'"

      view.RowFilter = String.Format(filter, ListingID, StartDate.ToString("MM/dd"))

      I'm making the assumption here that the CONVERT expression function would return a date in the format "MM/dd/yyyy", which I'm not sure of. But maybe some permutation of this idea will help.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups