truncate time from date in DataTable.Select()

E

Eddie

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
 
A

Arthur Yousif

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,037
Latest member
MozzGuardBugs

Latest Threads

Top