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
 Date with out time?

Author  Topic 

jonreeves
Starting Member

3 Posts

Posted - 2005-09-13 : 08:41:04
Hi

Looking to run a query that selects items from the current day. I have been using the GETDATE statement but due to this pulling through the time as well it doesnt not match the date in the table. Does anybody know how to just pull the date with out the time or any other way round this?

Thanks

Jon

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2005-09-13 : 08:45:40
select convert(varchar,getdate(),101)

He is a fool for five minutes who asks ,
but who does not ask remains a fool for life!

http://www.sqldude.4t.com
http://www.sqljunkies.com/weblog/sqldude
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-13 : 08:46:29
Select Dateadd(d,datediff(d,0,getdate()),0)


Madhivanan

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-13 : 08:47:24
harshal, I think Convert function is not neccessary

Madhivanan

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

jonreeves
Starting Member

3 Posts

Posted - 2005-09-13 : 08:51:06
Thanks guys

Could you possibly help me a little further, i now need to incororate that in to the query in running.

So far i have something simple like

Delete <Table Name>
Where <Filed Containing Date> = Getdate()

?????
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-13 : 08:55:13
Do you want to delete the records that are added today?
If so try this
But before running this take back up of that table and if the deletion is wrong then restore it

Delete <Table Name>
Where DateDiff(d,DateCol,GetDate())=0

Madhivanan

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

jonreeves
Starting Member

3 Posts

Posted - 2005-09-13 : 09:11:09
thanks that works perfectly
Go to Top of Page
   

- Advertisement -