Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6592209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:31:31+00:00 2026-05-25T17:31:31+00:00

I am trying to import some data from Sql Server 2008 into R, using

  • 0

I am trying to import some data from Sql Server 2008 into R, using RODBC with:

db <- odbcDriverConnect(connection = "Driver={SQL Server Native Client 10.0};Server=server; Database=db;Trusted_Connection=yes;")
results <- sqlQuery(db, "select timestamp from table where some-restriction")

The data is stored in a column of type “datetime”. All timestamps are in UTC, however my system timezone is CET. R converts all timestamps to values of type “POSIXct” “POSIXt” e.g:

“2011-01-01 07:24:12 CET”

“2011-01-01 08:35:10 CET”

“2011-01-01 09:02:50 CET”

timestamps are correct, timezone is wrong. Is seems to me that since timezone is not explicitly specified, R assigns to all timestamps my local timezone.

Is there any way the timezone of the data can be specified, so timezone information would be correct?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:31:31+00:00Added an answer on May 25, 2026 at 5:31 pm

    Pre R 3.1.0, and when this answer was originally written:

    For objects of class POSIXlt, you could modify the tzone attribute of the variable directly after importing the data:

    attr(results$timestamp,"tzone") <- "UTC"
    

    If your data is of class POSIXct this will change the data by the timezone offset, so convert to POSIXlt first by wrapping in an as.POSIXlt():

    results$timestamp <- as.POSIXlt(results$timestamp)
    

    eg:

    tm <- as.POSIXlt(Sys.time())
    tm
    [1] "2011-09-20 13:45:01 BST"
    attr(tm,"tzone") <- "UTC"
    tm
    [1] "2011-09-20 13:45:01 UTC"
    

    Since R 3.1.0 this behaviour has changed to use a component of the POSIXlt object rather than an attribute, and is obliquely referenced in the news by:

    Printing of date-times will make use of the time-zone abbreviation in
    use at the time, if known. For example, for Paris pre-1940 this could
    be LMT, PMT, WET or WEST. To enable this, the “POSIXlt” class has an
    optional component “zone” recording the abbreviation for each element.

    So now you would just use tm$zone <- "UTC"

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to import some data to SQL Server 2008 by means of
I'm trying to import some data from Excel to SQL Server, I have a
I am trying to import data from a FoxPro database into Sql Server however
I'm trying to import some data (using oracle sql developer) from a .csv file
I've been trying to import a table from oracle 10g into SQL Server 2005
I'm trying to import some data from excel into a database . i got
I'm using C# and .NET 3.5, trying to import some data from old dbf
I am trying to import data from a mySQL database into Microsoft SQL because
Im trying push some data into a CRM system via an XML import. I
I am trying to import an excel file into a data table using GemBox

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.