By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,659 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,659 IT Pros & Developers. It's quick & easy.

GetDate() with time-ignore

100+
P: 344
I'm trying to select all records inserted in a certain day, so comparing date only and ignore the time.
I searched for a function but didn't found.
I found this:
Expand|Select|Wrap|Line Numbers
  1. WHERE day([Date]) = day(GetDate()) AND month([Date]) = month(GetDate())
  2. AND year([Date]) = year(GetDate())
  3.  
Is to get the day, month and year then compare everyone of them.
My code getting more bigger!
Is there another easier way?

>>Edit<<
[Date] is a table in my database.
>>/Edit<<

Thanks,
Bassem
Mar 27 '09 #1
Share this Question
Share on Google+
7 Replies


ck9663
Expert 2.5K+
P: 2,878
Read this...and this



---- CK
Mar 28 '09 #2

100+
P: 344
The first link doesn't work, the other one make it more complex to me I'll try more with it.

Thanks,
Mar 28 '09 #3

ck9663
Expert 2.5K+
P: 2,878
Here you go...


--- CK
Mar 29 '09 #4

P: n/a
Here it is:

select Cast(Cast(DatePart(m, GetDate()) as varchar) + '/' + Cast(DatePart(d, GetDate()) as varchar) + '/' + Cast(DatePart(yy, GetDate()) as varchar) as datetime)
Oct 6 '10 #5

100+
P: 344
Will I still able to compare the datetime - the product of cast - to another one like a parameter?
Oct 6 '10 #6

100+
P: 152
gpl
From the link in post #4, this is what you need
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. DATEADD(dd, DATEDIFF(dd,0,@MyDate), 0)
  3. as "Midnight for the given day"
therefore your example now looks like
Expand|Select|Wrap|Line Numbers
  1. WHERE
  2. DATEADD(dd, DATEDIFF(dd,0,@MyDate), 0)=DATEADD(dd, DATEDIFF(dd,0,GetDate()), 0)
Oct 6 '10 #7

100+
P: 344
Thank you gpl.

Thanks ck9663 and zinkdude for your help.
Oct 6 '10 #8

Post your reply

Sign in to post your reply or Sign up for a free account.