September 23, 2008 at 12:03 am
I have a table that has the following field
[LOGDATETIMESTAMP] [datetime] NULL ,
which basically contains the date and time that the row was inserted
I want to return all of values where the datetimeStamp is = to the current day.
Is this possible using the getDate Function. I dont want to hard code the day as this will be used by a stored procedure
September 23, 2008 at 12:35 am
mpeters (9/23/2008)
I have a table that has the following field[LOGDATETIMESTAMP] [datetime] NULL ,
which basically contains the date and time that the row was inserted
I want to return all of values where the datetimeStamp is = to the current day.
Is this possible using the getDate Function. I dont want to hard code the day as this will be used by a stored procedure
Where LOGDATETIMESTAMP>=dateadd(day,datediff(day,0,getdate()),0) and LOGDATETIMESTAMP<dateadd(day,datediff(day,0,getdate()),1)
Failing to plan is Planning to fail
September 23, 2008 at 12:42 am
Hi mpeters
Here's the theory:
Get the current datetime using getdate()
Strip off the time component, which gives today
Add a day to the result, which gives tomorrow with no time component:
[font="Courier New"]DECLARE @Today DATETIME, @Tomorrow DATETIME
SET @Today = DATEADD(dd,DATEDIFF(dd, 0, GETDATE()), 0) -- '2008-09-23 00:00:00.000'
SET @Tomorrow = DATEADD(dd,1,@Today) -- '2008-09-24 00:00:00.000'
SELECT @Today, @Tomorrow -- Check the results
SELECT *
FROM yourtable
WHERE [LOGDATETIMESTAMP] >= @Today AND [LOGDATETIMESTAMP] < @Tomorrow[/font]
Cheers
ChrisM
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
September 24, 2008 at 12:23 am
Awesome, thank for all the help guys, thought there might have been a function that made it a bit easier
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply