Find records based on now minus 30 minutes when the server time is GMT

I am needing to find the records from a table based on the date created.  However the server time is GMT and is 6 hours ahead.  I need to find the records that have been created in the last 30 minutes when it is actually 6 hours 30 minutes ago.
FairfieldAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rajkumar GsSoftware EngineerCommented:
Please check whether this query will do.

Raj
SELECT * from urTable WHERE DATEDIFF(mi, CreatedDate, GETDATE()) <= 390

Open in new window

0
indianguru2Commented:
Try this
SELECT  *
FROM    Your_Table
WHERE   Date_Field = DATEADD(hour, -6, DATEADD(MINUTE, -30, GETDATE()))

Open in new window

0
FairfieldAuthor Commented:
I am not sure if I am doing this correctly, there are records that are created in the server database that are 5 hours in the future.  For example, there is one that is created at 5:10pm server time and my local time is 12:10pm.  Is this going to give me the records greater than 30 minutes ago?

select * from testdata
where dbo.audit.dte >= DATEADD(hour, -5, DATEADD(MINUTE, -30, GETDATE()))
0
dwkorCommented:
Something like that. Make sure you don't use datediff with field as the argument. It kills the index seek operation.
SELECT  *
FROM    Your_Table
WHERE   Date_Field between DATEADD(MINUTE, -390, GETDATE())) and DATEADD(MINUTE, -360, GETDATE()))

Open in new window

0
Rajkumar GsSoftware EngineerCommented:
So you can convert your time to server's time (+5 hours)
as DATEADD(hour, 5, GETDATE())

So query should be like shown below.

Check this query.

Raj
SELECT * FROM urTable
	WHERE DATEDIFF(mi, CreatedDate, DATEADD(hour, 5, GETDATE())) <= 30

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.