| 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 DateMadhivananFailing to plan is Planning to fail |
 |
|
|
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 applicationMadhivananFailing to plan is Planning to fail |
 |
|
|
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) |
 |
|
|
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? MadhivananFailing to plan is Planning to fail |
 |
|
|
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? MadhivananFailing to plan is Planning to fail
and he's still converting it to varchar which was against what you suggested |
 |
|
|
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. |
 |
|
|
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 ThanksMadhivananFailing to plan is Planning to fail |
 |
|
|
|