Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 16th, 2005, 11:46 PM
Authorized User
Join Date: Oct 2004
Location: , , Philippines.
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default GETDATE?

hi guys m having problem getting the current date of record
my command in query analyzer is

select * from genheader where date=getdate()

it doesnt show anthing

let say the date now is 2/17/05,
select * from genheader where date='2/17/05' then it display records but when i use getdate it doesnt show
when i run select * from genheader
it shows that date fields has
2005-02-17 00:00:00.000

i need to have a query that shows only the current date, hope u can help me :(

  #2 (permalink)  
Old February 17th, 2005, 02:31 AM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: May 2004
Location: India
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts

One possible solution could be converting and then comparing the date:

select * from genheader
where CONVERT(char(10),date,101) = CONVERT(char(10),GETDATE(),101)

Om Prakash
  #3 (permalink)  
Old February 17th, 2005, 08:05 AM
Friend of Wrox
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel

Sample Table Structure:
Create Table [TestDate] (
    [DateOfRegistration] [datetime],
    [Gender] [char] (1)

Sample records for testing
Insert into TestDate (DateOfRegistration,Gender) Values (getdate(),'M')
Insert into TestDate (DateOfRegistration,Gender) Values (getdate(),'M')

Method 1:
Select * from testdate where Convert(char(10),dateofregistration,101) = Convert(char(10),getdate(),101)

Method 2:
Select * from testdate where month(DateOfRegistration) = month(getdate()) and
day(DateOfRegistration) = day(getdate()) and
year(DateOfRegistration) = year(getdate())

Method 3:
Select * from testdate where datediff(d,dateofregistration,getdate()+1) = 1

I used to use the first method only almost always. But I have listed the other two methods which I know off for your reference. You could compare the performance benefits between the 3 methods and decide for yourself :)

Best Regards


Similar Threads
Thread Thread Starter Forum Replies Last Post
getdate Not Working ~Bean~ SQL Server 2000 4 September 7th, 2005 11:31 PM
Convert getdate() -> dd/mm/yyyy? minhpx SQL Language 1 January 3rd, 2005 09:30 AM
Using GETDATE in an In-Line function Mitch SQL Server 2000 13 March 25th, 2004 08:46 AM
seconds missing in getdate() stufflebeem SQL Server 2000 1 October 24th, 2003 04:52 PM
GETDATE() dose not......... arshad mahmood SQL Server 2000 2 August 19th, 2003 07:57 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.