Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi,


can any body tell me i wand records of particular date then how i can i get it?

i.e how to just compare to date not with date time

Select * from ABC Where TDate like '2010-01-09'

TDate is Datetime & value i pass by cmd parameter

plz reply soon ..

thanks in advance....
Posted

If are using SQL server, have a look at the Convert function documentation[^].

Look at date and time styles (especially code 101).
 
Share this answer
 
You can pass just the date from a DateTime object - it's a property.

DateTime dt = DateTime.Now;
CallMySql(dt.Date);
 
Share this answer
 
Select * from ABC Where convert(varchar(10),TDate,103) like '09/01/2009'
103=dd/MM/yyyy
 
Share this answer
 
I'd go with something like this:
SQL
DECLARE
	@Now datetime,
	@Today datetime,
	@Tomorrow datetime
SELECT
	@Now = GetDate(),
	@Today = DateAdd(dd, DateDiff(dd, 0, @Now), 0),
	@Tomorrow = DateAdd(DAY, 1, @Today)
SELECT * FROM ABC WHERE TDate >= @Today AND TDate < @Tomorrow

Note that I borrowed some of that code from ewbi.blogs.com. You'll note that I only calculate the date once (well, twice if you want to be picky). You will get better indexing performance if you apply calculations to the value you are comparing against rather than the column you are comparing against.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900