none
timezone in GetDate T-Sql

    Question

  • hi...

    i wanna save datetime in MSSQL in my country timezone form.

    i now use GetDate() function but it save date in server timezone and i need change o convert it to My zone time.

    example now in my country dateTiem is '2011-02-17 12:29:38.303' but in server is '2011-02-17 00:58:38.303'.

    i should save save first dateTiem not Secend.

    Plz Helppppp :(

    Thursday, February 17, 2011 9:01 AM

Answers

  • You can do DATEADD simply giving the Getdate().

    And I guess it is substring(A.TimeZone,6,2)

    Try like this,

    SELECT DATEADD(HOUR, CONVERT( int, substring(A.TimeZone,6,2)) , getdate() ) AS timeframe 
    FROM ( 
        select timeZone FROM Contact
         ) A


    Be the change you want.

     

    IF IT WORKS PLEASE MARK IT AS ANSWERED

    • Proposed as answer by Civic1986 Thursday, February 17, 2011 9:09 AM
    • Marked as answer by behrooz_bahrameh Thursday, February 17, 2011 11:51 AM
    Thursday, February 17, 2011 9:08 AM
  • Hi Behrooz.

    Use this query:

    SELECT DATEADD(mm,29,DATEADD(hh,11, GETDATE()))

     

     

    Cheers!

     


    Please mark as answer if this helps. Thank you.

    http://thebipalace.wordpress.com

    Thursday, February 17, 2011 10:37 AM

All replies

  • You can do DATEADD simply giving the Getdate().

    And I guess it is substring(A.TimeZone,6,2)

    Try like this,

    SELECT DATEADD(HOUR, CONVERT( int, substring(A.TimeZone,6,2)) , getdate() ) AS timeframe 
    FROM ( 
        select timeZone FROM Contact
         ) A


    Be the change you want.

     

    IF IT WORKS PLEASE MARK IT AS ANSWERED

    • Proposed as answer by Civic1986 Thursday, February 17, 2011 9:09 AM
    • Marked as answer by behrooz_bahrameh Thursday, February 17, 2011 11:51 AM
    Thursday, February 17, 2011 9:08 AM
  • Please always state what vesrion you are using

    Set up a table with all the worlds time-zone information and query that
    table.

    SQL Server 2008

    http://msdn.microsoft.com/en-us/library/ms186724.aspx


    Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/
    Thursday, February 17, 2011 9:13 AM
    Answerer
  • Hi Behrooz.

    Use this query:

    SELECT DATEADD(mm,29,DATEADD(hh,11, GETDATE()))

     

     

    Cheers!

     


    Please mark as answer if this helps. Thank you.

    http://thebipalace.wordpress.com

    Thursday, February 17, 2011 10:37 AM
  • You can do DATEADD simply giving the Getdate().

    And I guess it is substring(A.TimeZone,6,2 )

    Try like this,

    SELECT DATEADD(HOUR, CONVERT( int, substring(A.TimeZone,6,2)) , getdate() ) AS timeframe 
    FROM ( 
        select timeZone FROM Contact
         ) A


    Be the change you want.

     

    IF IT WORKS PLEASE MARK IT AS ANSWERED


    its better Use GateUTCDate instead of GetDate
    Thursday, February 17, 2011 11:53 AM