Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 date help

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-07-20 : 01:07:59
i remember seeing an article here on dates and sql but I can't find it - if someone can point me to it i would appreciate it.


i have a datetime field called mydate
how do I select all records where mydate=today (without looking at the time)

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-20 : 01:12:44
where mydate=dateadd(day,datediff(day,0,getdate()),0)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-07-20 : 01:18:39
that's not correct - it returns no records and there are definitely records dated today (but records have a date and time)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-20 : 02:00:50
Try a little harder please... (NOT Madhi)
where mydate>=dateadd(day,datediff(day,0,getdate()),0)


Peter Larsson
Helsingborg, Sweden

EDIT: Clarification of who to pay more effort
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-20 : 02:06:18
quote:
Originally posted by Peso

Try a little harder please...
where mydate>=dateadd(day,datediff(day,0,getdate()),0)


Peter Larsson
Helsingborg, Sweden


Thanks

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-20 : 02:08:10
quote:
Originally posted by esthera

i remember seeing an article here on dates and sql but I can't find it - if someone can point me to it i would appreciate it.


i have a datetime field called mydate
how do I select all records where mydate=today (without looking at the time)


Refer this article
www.sql-server-performance.com/fk_datetime.asp

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-07-20 : 02:14:34
thanks
Go to Top of Page
   

- Advertisement -