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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to get today's date in view design

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2008-02-28 : 09:58:23
I need to control DOF (date of order) which data type is datetime for today's date.
I use 1) or 2) but got null.
1) = getdate(),
2) = DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)
I use
between '2/28/2008' and '2/28/2008'
will get result.
How to get today's date?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-28 : 10:00:42
Sorry i just turned blind. Can you explein what you exactly want?
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2008-02-28 : 10:10:15
I need to create a view to get everyday's orders,add it into job agent and run every day 11:30PM. In [order day] column, I need to enter "Today" to control only today's order.
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-02-28 : 10:11:42
???????
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2008-02-28 : 10:33:11
For example, following codes will get nothing:

SELECT Order_Date, ID
FROM dbo.tblOrder
WHERE (Order_Date = GETDATE())

Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-02-28 : 10:40:42
[code]where
-- Order_Date after today at 00:00:00.000
Order_Date >= dateadd(dd,datediff(dd,0,getdate()),0) and
-- Order_Date before tomorrow at 00:00:00.000
Order_Date < dateadd(dd,datediff(dd,0,getdate())+1,0)[/code]


CODO ERGO SUM
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-28 : 10:44:31
For use with SP
DECLARE @Today DATETIME,
@Tomorrow DATETIME

SELECT @Today = DATEADD(DAY, DATEDIFF(DAY, '19000101', GETDATE()), '19000101'),
@Tomorrow = DATEADD(DAY, 1, @Today)

SELECT *
FROM Table1
WHERE DateColumn >= @Today
AND DateColumn < @Tomorrow
For use with view
SELECT	*
FROM Table1
WHERE DateColumn >= DATEADD(DAY, DATEDIFF(DAY, '19000101', GETDATE()), '19000101')
AND DateColumn < DATEADD(DAY, DATEDIFF(DAY, '18991231', GETDATE()), '19000101')



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2008-02-29 : 09:05:56
Thank you! They are working fine.
Go to Top of Page
   

- Advertisement -