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
 General SQL Server Forums
 New to SQL Server Programming
 Return records with current date

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2011-02-01 : 10:59:23
I want to write a select statement that returns all records with the current date. The date field is int 20110131.

I've tried

Select *
from oeordhdr
where month(getdate()) = substring(entered_dt,5,2) and
day(getdate() = substring(entered_dt,7,2) and year(getdate()) = left(entered_dt,4)

Doesn't seem to like the substring function.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-02-01 : 11:25:05
Which SQL Server version?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Vack
Aged Yak Warrior

530 Posts

Posted - 2011-02-01 : 11:27:12
SQL 2000
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-02-01 : 11:35:36
Select *
from oeordhdr
where convert(varchar(8),entered_dt) = dateadd(day,(datediff(day,0,getdate())),0)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-02-02 : 09:06:23
Select *
from oeordhdr
where entered_dt=CONVERT(char(8),getdate(),112)*1

Madhivanan

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

chapm4
Yak Posting Veteran

58 Posts

Posted - 2011-09-26 : 13:30:47
Is there a difference if I am using datetime instead of int and using sql server 2005 instead of 2000?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-09-26 : 14:11:10
hey visakh - it is ok if you like to answer this


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-09-26 : 14:27:52
This will answer your question and many more questions:
http://beyondrelational.com/blogs/madhivanan/archive/2010/05/25/understanding-datetime-column-part-i.aspx


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

chapm4
Yak Posting Veteran

58 Posts

Posted - 2011-09-26 : 15:34:53
Thanks
Go to Top of Page
   

- Advertisement -