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
 UTC to Indian Standar Time(+5:30)

Author  Topic 

bhanu2217
Starting Member

35 Posts

Posted - 2010-05-22 : 02:29:37
All my dates/times are stored in UTC format in database.
Is it possible to convert them into Indian standard time in query itself?(while i am retrieving the records)

www.JamboreeBliss.com

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-05-22 : 03:18:12
you can use dateadd function and add the minutes..

Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-05-22 : 03:18:44
The only way would be to use the DATEADD function. You could create your own user defined function and do something like this:
CREATE FUNCTION dbo.UTC2Indian (
@UTCTime datetime)
RETURNS datetime
AS

BEGIN

SET @UTCTime = DATEADD(mm, 330, @UTCTime)
RETURN @UTCTime

END
And then in your query just do like this SELECT myUTCTimeColumn, dbo.UTC2Indian(myUTCTimeColumn) FROM table

- Lumbago
My blog (yes, I have a blog now!) -> www.thefirstsql.com
Go to Top of Page

bhanu2217
Starting Member

35 Posts

Posted - 2010-05-22 : 03:43:08
Thank You.

www.JamboreeBliss.com
Go to Top of Page

bhanu2217
Starting Member

35 Posts

Posted - 2010-05-22 : 03:49:32
Small problem here my Year become 2037 instead of 2010 if u use the above procedure and query

www.JamboreeBliss.com
Go to Top of Page

bhanu2217
Starting Member

35 Posts

Posted - 2010-05-22 : 03:52:29
6 months are added to the month also.

www.JamboreeBliss.com
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-05-22 : 04:04:16
use

SET @UTCTime = DATEADD(mi, 330, @UTCTime)
Go to Top of Page

bhanu2217
Starting Member

35 Posts

Posted - 2010-05-22 : 06:25:20
Thank You.

www.JamboreeBliss.com
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-05-22 : 06:27:18
Glad to help
Go to Top of Page
   

- Advertisement -