Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > truncate time from date in DataTable.Select()

Reply
Thread Tools

truncate time from date in DataTable.Select()

 
 
Eddie
Guest
Posts: n/a
 
      12-23-2003
I have a DataTable.Select() statement with a DateTime field that is
being compared to a Date:

Dim drCal as DataRow() = tblCal.Select("CalendarItemDate
='12/1/2003'", "CalendarItemDate", DataViewRowState.CurrentRows)

This never returns any rows because all the CalendarItemDate fields
that contain the date 12/1/2003 also contain a time component! I
searched until I was SICK and could not find how to truncate the time
from the DateTime field in the Select expression.

I would prefer to do it in the Select expression, but if I have to add
another field to the SQL statement that populates the DataSet, I guess
that will have to do. However, MS SQL 2000 no longer has the Trunc()
function!! I guess I have to use Round(n,0,1)??

Thanks in advance for any clues.

Cheers
Eddie
 
Reply With Quote
 
 
 
 
Arthur Yousif
Guest
Posts: n/a
 
      12-23-2003
Hi,

I don't normally set up a select like this, but you can try an old trick
like:

CalendarItemDate >= '12/1/2003 00:00:00' AND
CalendarItemDate <= '12/1/2003 23:59:59'

I'm surprised it's not working. Have you tried the select manually in Query
Analyzer? The select should match regardless of the time portion as long as
the date portion matches.

See the Transact-SQL help and look up the DatePart. You can use that to
construct a date-only value. Sorry I wasn't more helpful. I hope you get
it working, I know how frustrating this can be. Good luck.

--
Arthur


"Eddie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> I have a DataTable.Select() statement with a DateTime field that is
> being compared to a Date:
>
> Dim drCal as DataRow() = tblCal.Select("CalendarItemDate
> ='12/1/2003'", "CalendarItemDate", DataViewRowState.CurrentRows)
>
> This never returns any rows because all the CalendarItemDate fields
> that contain the date 12/1/2003 also contain a time component! I
> searched until I was SICK and could not find how to truncate the time
> from the DateTime field in the Select expression.
>
> I would prefer to do it in the Select expression, but if I have to add
> another field to the SQL statement that populates the DataSet, I guess
> that will have to do. However, MS SQL 2000 no longer has the Trunc()
> function!! I guess I have to use Round(n,0,1)??
>
> Thanks in advance for any clues.
>
> Cheers
> Eddie



 
Reply With Quote
 
 
 
Reply

Thread Tools

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
[Q] algorithm to truncate date to beginning of week? Chuck Remes Ruby 7 02-09-2010 08:35 PM
w3.org suggestion .. page, date, time and topic, date, time code (wish list). Keith Cochrane HTML 2 08-06-2006 06:57 AM
covert time from date Hour min sec format to epoch time i.e time since 1 jan 1970 in C Summu82 C Programming 5 06-07-2006 02:51 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Date & Time chooser for java 1.1 - using only the mouse to select time & date Chris Berg Java 0 10-27-2003 10:59 PM



Advertisments