DateTime of Now in a DataColumn expression

  • Thread starter Thread starter Jon Fairchild
  • Start date Start date
J

Jon Fairchild

I would like to calculate a column by subtracting a date column from
the current date/time. The expression would like something like:

Now - TIME_OUTAGE

Unfortunately, the 'Now' function is not recognized by DataColumn
expressions as it is in VBScript. Anyone know a way to make this work?

Thanks,
Jon
 
Hi Bin:

I tried solving this for him and I just created an extra column, setting the
expression to DateTime.Now and everything was fine. I tested this much and
it worked great. However whenever I tried doing the subtracting, it kept
telling me that "-" was invalid between two date and times fields.

I've tried everything I know and it's driving me nuts...... I used that
below and even used the # # like the expression syntax references and still
no dice.

Have you gotten that to work? I may just have tunnelvision b/c I've been
trying this for a few hours now.

Let me know if you can think of anything.

Cheers,

Bill
 
Hi Jon,

You might consider to get rid of Expressions and use code to calculate and
fill the data..
 
Miha Markic said:
Hi Jon,

You might consider to get rid of Expressions and use code to calculate and
fill the data..

Hi Miha, Bin

Calculated columns are not meeting our needs, so we may be heading the
direction of using code as you have suggested. Since we are talking
about date substraction from DateTime.Now, this field must be updated
periodically for the value to be correct. I am thinking we would
calculate the field whenever a row is created, updated, and also based
on a timer.

I am interested to hear your ideas on how to implement a code
solution.

Thanks,
Jon
 
Hi Jon,

Jon Fairchild said:
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Hi Jon,

You might consider to get rid of Expressions and use code to calculate and
fill the data..

Hi Miha, Bin

Calculated columns are not meeting our needs, so we may be heading the
direction of using code as you have suggested. Since we are talking
about date substraction from DateTime.Now, this field must be updated
periodically for the value to be correct. I am thinking we would
calculate the field whenever a row is created, updated, and also based
on a timer.

I am interested to hear your ideas on how to implement a code
solution.

For first two variants you would just implement table events.
For periodicaly, hmmm. Why do you need this field?
Is it for display only?
Then you might implement it only on UI layer and not in table itself.
 
Miha Markic said:
Hi Jon,

For first two variants you would just implement table events.
For periodicaly, hmmm. Why do you need this field?
Is it for display only?
Then you might implement it only on UI layer and not in table itself.

Hi Miha,

That's correct, this DURATION field is for presentation only. So I
could generate the value on the UI layer as you suggest. However, we
want to present DURATION along with the other table fields in a
data-bound grid. I would have to add an extra column to the grid in
addition to the data-columns. I have ideas on how to approach this,
but they seem like a lot of work to solve a simple problem.

That's why calculated columns were such an intriguing solution.
Hopefully they will become more powerful in future releases of
ADO.NET...

Thanks for your kind replies,
Jon
 
Back
Top