SQL time adjust from server time
Store all of your data/times as the server date/time. Then when
viewed do this time correction to give the user the correct time for
their location. This keeps all times consistent where ever they are viewed
WITH the a view and HOUR change.
Date and times are stored at the server, where ever in the country/timezone it
might be thus a time adjust is needed when viewed in a different time
zone. The simple solution is build a view of your table with a DATATADD
applied to your stored time
in the database to adjust the hour from the server time to the time zone location.
Syntax DATEADD
( datepart , number, date
)
| Datepart |
Abbreviations |
| Year |
yy, yyyy |
| quarter |
qq, q |
| Month |
mm, m |
| dayofyear |
dy, y |
| Day |
dd, d |
| Week |
wk, ww |
| Hour |
hh |
| minute |
mi, n |
| second |
ss, s |
| millisecond |
ms |
| DATEADD([hour], - 1, dbo.YourDateTimeColumn)
--hour adjust in a view
|
|