PC Review


Reply
Thread Tools Rate Thread

How to use DateTime constants in DataTable.Compute or Filter

 
 
aw
Guest
Posts: n/a
 
      21st May 2004
There are some informations about it in Framework Help but they are
incomplete, I think. Some examples:
1. compute property: datetime is without apostrphes as MM/dd/yy
2. expression property: datetime is in hashes as MM/dd/yy
3. null datetime as ## doesn't work
4. when I use DateTime.ToString() results depends on international
settings or kind of operation system.
5. I couldn't find any information about such datetime format in msdn

datetime.ToString("u") often works but not always - on computers
having thesame international settings and time zone (I use it with Polish
settings).
myDate.ToString("u").Replace("Z","") - as well. Sometimes should be
YYYY-MM-DD format when in os I have DD-MM-YYYY
American format MM/DD/YYYY works - but I don't know if always.

May be someone knows how to use it?
Thx in advance

--------------------------------------------------------------------------
Hi,
AW


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      21st May 2004
Hi AW,

I think it is better as you ask question like this next time in the
newsgroup
microsoft.public.dotnet.languages.vb

However working with dates did look for me as well very complex, however the
possibilities are endless.

dim wp as string = Now.toString("dd-MM-yyyy")

gives 21-05-2004

http://msdn.microsoft.com/library/de...tringTopic.asp

Ma nadzieje, ze to pomoze?

Cor


 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      21st May 2004
Cor Ligthert <(E-Mail Removed)> wrote:
> I think it is better as you ask question like this next time in the
> newsgroup
> microsoft.public.dotnet.languages.vb


Why? It's an ADO.NET question.

> However working with dates did look for me as well very complex, however the
> possibilities are endless.
>
> dim wp as string = Now.toString("dd-MM-yyyy")
>
> gives 21-05-2004
>
> http://msdn.microsoft.com/library/de...ary/en-us/cpre
> f/html/frlrfSystemDateTimeClassToStringTopic.asp
>
> Ma nadzieje, ze to pomoze?


I think you've missed part of the point of the question, which is
whether the RowFilter expression's format is *always* meant to be in US
format (as #MM/dd/yyyy#) or whether it depends on culture. I suspect
it's always meant to be in the US format, given the documentation, but
it's not clear.

There's also the question of how times should be represented, as that
isn't covered (as far as I can see) in the documentation.

Basically the DataView.RowFilter/DataColumn.Expression etc
documentation is significantly lacking - but then, I believe the
mechanism is pretty significantly lacking in the first place, as it
would make a lot of sense to *also* allow row filters, computed
expressions etc to be written in actual code rather than just in text
expressions. I haven't checked whether or not this will be available in
ADO.NET 2.0, but I'm sure I'm not the only person to want it.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      21st May 2004
Hi,

I think that you should use #mm/dd/yyyy# notation as described in
DataColumn.Expression help topic.

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

"aw" <(E-Mail Removed)> wrote in message
news:c8kapk$6hq$(E-Mail Removed)...
> There are some informations about it in Framework Help but they are
> incomplete, I think. Some examples:
> 1. compute property: datetime is without apostrphes as MM/dd/yy
> 2. expression property: datetime is in hashes as MM/dd/yy
> 3. null datetime as ## doesn't work
> 4. when I use DateTime.ToString() results depends on international
> settings or kind of operation system.
> 5. I couldn't find any information about such datetime format in

msdn
>
> datetime.ToString("u") often works but not always - on computers
> having thesame international settings and time zone (I use it with Polish
> settings).
> myDate.ToString("u").Replace("Z","") - as well. Sometimes should be
> YYYY-MM-DD format when in os I have DD-MM-YYYY
> American format MM/DD/YYYY works - but I don't know if always.
>
> May be someone knows how to use it?
> Thx in advance
>
> --------------------------------------------------------------------------
> Hi,
> AW
>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      21st May 2004
Hi Jon,

> > I think it is better as you ask question like this next time in the
> > newsgroup
> > microsoft.public.dotnet.languages.vb

>
> Why? It's an ADO.NET question.
>

I did not say that it is not an ado.net question, I am not as good as you
that without people write one syllable about it I know that this is an
ADO.NET question about.

However what was asked would most probably gets better answers in the
language.vb newsgroup. Although when needed I can cover them all as well
here.

Cor




 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      21st May 2004
<"Miha Markic [MVP C#]" <miha at rthand com>> wrote:
> I think that you should use #mm/dd/yyyy# notation as described in
> DataColumn.Expression help topic.


And should that be used regardless of culture? That's what isn't clear.

It's also not clear how the time component should be specified.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      21st May 2004
Cor Ligthert <(E-Mail Removed)> wrote:
> > > I think it is better as you ask question like this next time in the
> > > newsgroup
> > > microsoft.public.dotnet.languages.vb

> >
> > Why? It's an ADO.NET question.
> >

> I did not say that it is not an ado.net question, I am not as good as you
> that without people write one syllable about it I know that this is an
> ADO.NET question about.


Eh? It was fairly *clearly* an ADO.NET question, given the title. No
psychic powers required.

> However what was asked would most probably gets better answers in the
> language.vb newsgroup. Although when needed I can cover them all as well
> here.


But what on earth does it have to do with VB? From the post, the OP may
not even *be* a VB.NET programmer.

The post was much more on-topic here than it would have been in the VB
group, and here it reached everyone interested in ADO.NET, not just VB
programmers.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
aw
Guest
Posts: n/a
 
      21st May 2004
Thx for all.
AW


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      21st May 2004
Hi John,

Now I understand, you want to know how to do this.

By instance in this way roughly created using VB.net

Most is of course VB.net code.

AW
Nie zauwazylem tematu. :-)

I hope this helps?

Cor

\\\
Dim dt As New DataTable
Dim dc As New DataColumn("OHM")
dc.DataType = GetType(System.Int32)
Dim dd As New DataColumn("OHH")
dd.DataType = GetType(System.DateTime)
dt.Columns.Add(dc)
dt.Columns.Add(dd)
For i As Integer = 0 To 24
dt.Rows.Add(dt.NewRow)
dt.Rows(i)(0) = 100
dt.Rows(i)(1) = CDate("01-01-2003").AddMonths(i)
Next
' This is the sample
Dim Thismonth As String = Now.ToString("#MM/dd/yy#")
Thismonth = Thismonth.Replace("-", "/")
MessageBox.Show(dt.Compute("Sum(OHM)", "OHH < " _
& Thismonth).ToString)
////



 
Reply With Quote
 
aw
Guest
Posts: n/a
 
      21st May 2004
> Now I understand, you want to know how to do this.
> By instance in this way roughly created using VB.net
> Most is of course VB.net code.
>
> AW
> Nie zauwazylem tematu. :-)
>
> I hope this helps?
>
> Cor
>
> \\\
> Dim dt As New DataTable
> Dim dc As New DataColumn("OHM")
> dc.DataType = GetType(System.Int32)
> Dim dd As New DataColumn("OHH")
> dd.DataType = GetType(System.DateTime)
> dt.Columns.Add(dc)
> dt.Columns.Add(dd)
> For i As Integer = 0 To 24
> dt.Rows.Add(dt.NewRow)
> dt.Rows(i)(0) = 100
> dt.Rows(i)(1) = CDate("01-01-2003").AddMonths(i)
> Next
> ' This is the sample
> Dim Thismonth As String = Now.ToString("#MM/dd/yy#")
> Thismonth = Thismonth.Replace("-", "/")
> MessageBox.Show(dt.Compute("Sum(OHM)", "OHH < " _
> & Thismonth).ToString)
> ////



Sorry, I use C#, but all Your messages were useful. Now we try to test
static public string ToStringCdate(object o)

{

DateTime dt=ToDateTime(o);

if(dt==DateTime.MinValue) return "''";

return "#"+dt.ToString("MM/dd/yyyy")+"#";

}

format in our application. We use MinValue as null.
--
Hi
AW


 
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
datatable.compute Chuck Hecht Microsoft Dot NET Compact Framework 1 28th Aug 2007 04:45 AM
DataTable.Compute() question SpaceMarine Microsoft Dot NET Framework 5 22nd Aug 2007 09:41 AM
DataTable.Compute() question SpaceMarine Microsoft ADO .NET 5 22nd Aug 2007 09:41 AM
datatable.compute method =?Utf-8?B?RGF2aWQgQW5kZXJzb24=?= Microsoft Dot NET 1 8th Jun 2005 12:16 PM
Datatable.Compute and Sorting scorpion53061 Microsoft ADO .NET 4 10th May 2004 07:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:10 AM.