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
 Statement Help: Showing Time Minus 2 Hours

Author  Topic 

MrIxi
Starting Member

5 Posts

Posted - 2008-10-31 : 08:55:16
Greetings!

I am displaying the date/time of transactions in my client's admin area. Since my client lives in the Pacific time zone, she wants the time figure to always display as PST, regardless of the client's time zone. The server is in the Central time zone, so I want to be able to subtract two hours from the displayed time.

Here's the part of the select statement that concerns the date field 'createDate'. How would I accomplish this?

SELECT TOP (100) PERCENT id, CONVERT(varchar, createDate, 100) AS Date


Thanks for the assist!

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-31 : 09:10:59
SELECT TOP (100) PERCENT id, CONVERT(varchar, dateadd(hour,-2,createDate, 100)) AS Date


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-31 : 09:13:25
Also dont convert the date to varchar. Format dates in the front end application

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

MrIxi
Starting Member

5 Posts

Posted - 2008-10-31 : 11:43:03
Thank you Madhivanan! Works brilliantly.

PS. I had to make a slight modification to your CONVERT parameters:

CONVERT(varchar, DATEADD(hour, - 2, createDate), 100)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-01 : 02:45:06
quote:
Originally posted by MrIxi

Thank you Madhivanan! Works brilliantly.

PS. I had to make a slight modification to your CONVERT parameters:

CONVERT(varchar, DATEADD(hour, - 2, createDate), 100)


What is the modification except upper case for DATEADD?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-01 : 02:46:53
quote:
Originally posted by madhivanan

quote:
Originally posted by MrIxi

Thank you Madhivanan! Works brilliantly.

PS. I had to make a slight modification to your CONVERT parameters:

CONVERT(varchar, DATEADD(hour, - 2, createDate), 100)


What is the modification except upper case for DATEADD?

Madhivanan

Failing to plan is Planning to fail


and he's still converting it to varchar which was against what you suggested
Go to Top of Page

MrIxi
Starting Member

5 Posts

Posted - 2008-11-01 : 07:53:34
Original: CONVERT(varchar, dateadd(hour,-2,createDate, 100))
Modified: CONVERT(varchar, DATEADD(hour,-2,createDate), 100)

I only discovered it because the error said that DATEADD needs three arguments.

Thanks again.

visakh16: Yes, I left varchar because it works fine as is.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-01 : 08:42:40
quote:
Originally posted by MrIxi

Original: CONVERT(varchar, dateadd(hour,-2,createDate, 100))
Modified: CONVERT(varchar, DATEADD(hour,-2,createDate), 100)

I only discovered it because the error said that DATEADD needs three arguments.

Thanks again.

visakh16: Yes, I left varchar because it works fine as is.


Ok Thanks

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -