Nubkadiya
Nubkadiya

Reputation: 3475

How to get only the date from the sql server

this is what i want. but i have put only a specified date.

SELECT BookName, Author, BookPrice 
FROM Book 
WHERE Book.Book_ID = ( 
    SELECT Book_ID 
    FROM Temp_Order 
    WHERE Temp_Order.User_ID = 25 AND Temp_Order.OrderDate='3/24/2010'
)

this is the date function i used. but it takes the time also. how to stop it. please help me

SELECT Book_ID, BookName,Author,BookPrice 
FROM Book INNER JOIN FavCategory ON Book.Category_ID = FavCategory.Category_ID 
WHERE FavCategory.User_ID = " + useridlabel.Text + " AND 
      OrderDate =  **GETDATE()** 

Upvotes: 1

Views: 2455

Answers (5)

David Espart
David Espart

Reputation: 11780

This is a classic question for Sql Server versions previous 2008:

SELECT Book_ID, BookName,Author,BookPrice 
FROM Book INNER JOIN FavCategory ON Book.Category_ID = FavCategory.Category_ID 
WHERE FavCategory.User_ID = " + useridlabel.Text + " 
AND CONVERT(nvarchar, OrderDate, 111) = CONVERT(nvarchar, GETDATE(), 111)

Depending on the code (111) you put at the end you can format the date for the zone where you are.

Upvotes: 0

LukeH
LukeH

Reputation: 269368

SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))

Upvotes: 0

eKek0
eKek0

Reputation: 23289

Try:

  OrderDate =  CONVERT(varchar, GETDATE(), 101)

wich returns the date in format mm/dd/yyyy, or choose a convertion format from here.

Upvotes: 0

Jhonny D. Cano -Leftware-
Jhonny D. Cano -Leftware-

Reputation: 18013

This one is for Sql Server 2000:

SELECT CONVERT(DATETIME, FLOOR(CONVERT(FLOAT, GETDATE())))

Upvotes: 3

Ryan Abbott
Ryan Abbott

Reputation: 5417

SELECT CONVERT (date, GETDATE())

MSDN

Upvotes: 2

Related Questions