#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    18
    Rep Power
    0

    How get UTC-timestamp


    Hello,

    is there a way to get in Firebrid-SQL the current UTC-timestamp?
    current_timestamp is the computertime, where firebird is hosted, or?

    best regards

    Boris
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Location
    Plovdiv. Bulgaria
    Posts
    226
    Rep Power
    12
    Originally Posted by Boris0815
    Hello,
    is there a way to get in Firebrid-SQL the current UTC-timestamp?
    current_timestamp is the computertime, where firebird is hosted, or?
    best regards
    Boris
    Yes the currnet_timestamp is the time of the machine where Firebird is hosted.

    If you use FB 2.1.x and you know the time zone of that machine you can use

    SELECT
    DATEADD(HOUR,-CAST(:HOURS AS INTEGER),CURRENT_TIMESTAMP)
    FROM RDB$DATABASE


    If the machine is GMT + 2 set :HOURS to 2
    If it's GMT-3 set HOURS to -3.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    18
    Rep Power
    0
    Thanks for your answer.

    This will work, but the problem is, at designtime I don't know which GMT the host computer has.
    Many copys of my database will run on different computers worldwide.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Location
    Plovdiv. Bulgaria
    Posts
    226
    Rep Power
    12
    Originally Posted by Boris0815
    Thanks for your answer.

    This will work, but the problem is, at designtime I don't know which GMT the host computer has.
    Many copys of my database will run on different computers worldwide.
    Make this value configurable in the application and store it in the database. After that used wherever you want.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    18
    Rep Power
    0
    Hello,

    a finished function from Firebird would please me better, but it works.

    Thanks for your help.

    best regards

    Boris
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Location
    Plovdiv. Bulgaria
    Posts
    226
    Rep Power
    12
    Originally Posted by Boris0815
    Hello,

    a finished function from Firebird would please me better, but it works.

    Thanks for your help.

    best regards

    Boris
    You can write an own UTF and use it.
  12. #7
  13. Modding: Oracle MsSQL Firebird
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2001
    Location
    Outside US
    Posts
    8,527
    Rep Power
    539
  14. #8
  15. #9
  16. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    18
    Rep Power
    0
    Maybe I'm completely wrong, but aren't you after the client UTC timestamp, regardless of what the server timestamp is?
    The Database and the client are always on the same computer, so server and client timestamp are the same.
    I need the UTC, because I synchronize different Firebirds worldwide.
  17. #10
  18. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    1
    Rep Power
    0
    The .NET framework, among others, can help you to determine your timezone's offset from UTC:

    Code:
    public static double OffsetFromUtc()
    {                          
        return (DateTime.Now - DateTime.UtcNow).TotalHours;          
    }
    (Yes, there are fractional timezones, e.g. Nepal has UTC + 5:45!)

    Then, you get your Firebird UTC timestamp via

    Code:
    DATEADD(minute, -x*60, current_timestamp)
    where x is the result of the above method, which could be encapsulated within a tiny DLL, for instance.

    Hope this helps;
    hanzzoid.

IMN logo majestic logo threadwatch logo seochat tools logo