PC Review


Reply
Thread Tools Rate Thread

DateTime of Now in a DataColumn expression

 
 
Jon Fairchild
Guest
Posts: n/a
 
      21st Apr 2004
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmluIFNvbmcsIE1DUA==?=
Guest
Posts: n/a
 
      21st Apr 2004
Hi, Jon

There is no datetime function for a DataColumn Expression. Check:
http://msdn.microsoft.com/library/de...ssionTopic.asp

What you might do is:
dataColumn.Expression = "'" & DateTime.Now() & "'- TIME_OUTAGE"

Bin Song, MCP
 
Reply With Quote
 
William Ryan eMVP
Guest
Posts: n/a
 
      22nd Apr 2004
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
"Bin Song, MCP" <(E-Mail Removed)> wrote in message
news:66F24815-12AA-45CC-A6A7-(E-Mail Removed)...
> Hi, Jon
>
> There is no datetime function for a DataColumn Expression. Check:
>

http://msdn.microsoft.com/library/de...ssionTopic.asp
>
> What you might do is:
> dataColumn.Expression = "'" & DateTime.Now() & "'- TIME_OUTAGE"
>
> Bin Song, MCP



 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      22nd Apr 2004
Hi Jon,

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

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"Jon Fairchild" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Jon Fairchild
Guest
Posts: n/a
 
      22nd Apr 2004
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:<(E-Mail Removed)>...
> Hi Jon,
>
> You might consider to get rid of Expressions and use code to calculate and
> fill the data..
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & software development
> miha at rthand com
> www.rthand.com


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
 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      23rd Apr 2004
Hi Jon,

"Jon Fairchild" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Miha Markic [MVP C#]" <miha at rthand com> wrote in message

news:<(E-Mail Removed)>...
> > Hi Jon,
> >
> > You might consider to get rid of Expressions and use code to calculate

and
> > fill the data..
> >
> > --
> > Miha Markic [MVP C#] - RightHand .NET consulting & software development
> > miha at rthand com
> > www.rthand.com

>
> 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 [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com


 
Reply With Quote
 
Jon Fairchild
Guest
Posts: n/a
 
      23rd Apr 2004
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:<#Nx7$(E-Mail Removed)>...
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataColumn.Expression with DateTime Datatype Matt F Microsoft VB .NET 11 15th Mar 2007 04:19 PM
Calculations with DateTime fields using DataColumn.Expression stri =?Utf-8?B?TWF0dA==?= Microsoft Dot NET Framework Forms 2 2nd Jan 2005 06:19 AM
subtracting DateTime fields in a DataColumn expression Jon Fairchild Microsoft ADO .NET 1 22nd Apr 2004 12:15 AM
datetime datacolumn Maurizio Microsoft ADO .NET 0 25th Aug 2003 09:44 PM
DataColumn Expressions and DateTime William Ryan Microsoft ADO .NET 0 7th Aug 2003 09:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:57 AM.