Calculate DateTime type in DataColumn.Expression RRS feed

  • Question

  • Is there a way that I can add/substract days from DateTime value in DataColumn.Expression? Like: "TODAY + 5", where I have a column TODAY.

    I am using DataColumn.Expression to evaluate whether value match specified condition. It's very handy but then I run into DateTime tyep and don't know how to work around it.



    Monday, April 21, 2008 7:28 PM

All replies

  • Have you looked at DateTime.AddDays()?

    Monday, April 21, 2008 8:17 PM
  • Thanks for your reply. But I am using expression string in DataColumn.Expression property, not in c# code. I found this link: http://msdn2.microsoft.com/en-us/library/system.data.datacolumn.expression(VS.71).aspx,

    but it doesn't tell me anything about how to change a DateTime type value.

    Monday, April 21, 2008 9:27 PM
  • Are you retrieving the data from a database or adding it "on the fly". If you're retrieving data from a database you could probably perform this calculation in a SQL statement (depending upon the database you are working with).
    Wednesday, April 23, 2008 12:22 PM

    We are adding the data "on the fly". In our situation here we can't use SQL statement for this.



    Wednesday, April 23, 2008 12:57 PM
  • I don't believe that Expression will handle date calculations. You will probably need to calculate the date before adding it to the DataRow.
    Wednesday, April 23, 2008 2:19 PM