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
 GETDATE()

Author  Topic 

Ads
Starting Member

23 Posts

Posted - 2012-01-26 : 05:45:15
Hi,

I'm trying to select records for deliveries each day, the date base format is: yyyy-mm-dd hh:mm:ss.mmm however I dont want it to select by time but just the date.

I already have the following code for the date: replace(convert(varchar, getdate(), 111), '/', '-') how can I skip the search for the time?

Many thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-01-26 : 05:52:14
Try:
where datetimeColumn >= dateadd(d,datediff(d,0,getdate()),0) and datetimeColumn < dateadd(d,datediff(d,0,getdate())+1,0)




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

Ads
Starting Member

23 Posts

Posted - 2012-01-26 : 06:28:50
Thanks for your quick reply!

Do I just replace the following code:

Where [efacdb].[dbo].[shipments].[shipmentdate] = replace(convert(varchar, getdate(), 111), '/', '-')

Very new to SQL.

Thanks again.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-01-26 : 06:55:16
just replace datetimeColumn by [efacdb].[dbo].[shipments].[shipmentdate]


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

Ads
Starting Member

23 Posts

Posted - 2012-01-26 : 07:42:47
Works a treat! thanks very much.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-26 : 08:48:00
quote:
Originally posted by Ads

Thanks for your quick reply!

Do I just replace the following code:

Where [efacdb].[dbo].[shipments].[shipmentdate] = replace(convert(varchar, getdate(), 111), '/', '-')

Very new to SQL.

Thanks again.


does shipmentdate have a time part?
as long as it doesnt store timepart you're safe
if not you may be better off using logic that Fred suggested ie using open interval >= and <

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-26 : 08:49:12
also no need of converting to varchar for stripping time

see
http://visakhm.blogspot.com/2010/01/some-quick-tips-for-date-formating.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-01-26 : 09:19:31
quote:
Originally posted by Ads

Works a treat! thanks very much.


Glad it works for you


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

- Advertisement -