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
 General SQL Server Forums
 New to SQL Server Programming
 Adding a time in a query

Author  Topic 

lez_s
Starting Member

3 Posts

Posted - 2012-03-14 : 15:06:37
Hello,

I need to add 3 hours into a query so it show West Coast time and not East Coast, but no idea how.

e.g. 2012-1-2 14:28:10 to show 2012-1-2 17:28:10

Thanks

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-03-14 : 15:36:50
You can use the dateadd function:
DATEADD(hour,3,EastCostTime)
That adds 3 hours. But, shouldn't you be subtracting 3 hours rather than adding?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-03-14 : 15:37:21
Actually west coast time (Pacific) is 3 hours behind east coast (Eastern). Nevertheless:

SELECT DATEADD(hour, 3, datevalue)
--e.g.:
SELECT DATEADD(hour, 3, '2012-1-2 14:28:10')

Go to Top of Page

lez_s
Starting Member

3 Posts

Posted - 2012-03-14 : 15:46:07
Thanks for your help so far. below is the first line and in the stamp column is where the date and time is, would I just add in there.

By the way, 2nd day in the new job!!!

SELECT Count(DISTINCT guid1), DATEPART(DAY,stamp) FROM.......
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-14 : 15:54:28
quote:
Originally posted by lez_s

Thanks for your help so far. below is the first line and in the stamp column is where the date and time is, would I just add in there.

By the way, 2nd day in the new job!!!

SELECT Count(DISTINCT guid1), DATEPART(DAY,DATEADD(hh,3,stamp)) FROM.......


is this what you're after?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

lez_s
Starting Member

3 Posts

Posted - 2012-03-14 : 16:03:27
Thanks.
Go to Top of Page
   

- Advertisement -