Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Formatting datetime variable for display in a timezone different than UTC

    Dear Statalist,
    I struggle with a question whether there is a possibility in Stata to get a date which is properly stored in datetime format, to be displayed according to a different time zone than UTC. For example, I have a variable stored in UTC, but wish for it to be displayed in CET time. I bother, because for the data deposit I need to provide a variable containing real time (in UTC terms), but formatted for display in local time. I searched the internets, but could not find any reasonable clue to deal with this problem.

  • #2
    UTC and CET are not part of any display format as far as I know In order to see a different time, you need to change the variable or constant concerned. This is all part of a general principle that changing a display format does not change what is stored, only what is shown; so to change what is stored, you need in this case to add the equivalent of 1 hour, namely 3.6 million ms, to the time,

    Code:
    . di msofhours(1)
    3600000

    Comment


    • #3
      To elaborate (I hope) on what Nick is saying, there is no such thing as a "real time" in Stata, other software, or really anywhere in the universe -- unless perhaps we agree that Big Bang is absolute 0. Time is relative (not only) in the sense that it is defined relative to an arbitrary time point. In Stata, that time point is the first millisecond of January 1, 1960. Every integer other than 0 then represents 1 millisecond before or after that time point. Whether January 1, 1960, 00:00:00 is UTC or CET or some other time zone is irrelevant because the units of time (milliseconds) are the same for any time zone.

      Comment


      • #4
        Thank you Nick and Daniel. I just wanted to be 100% sure that I am not missing anything. Time is relative, and I can add one hour to get my CET time, for sure. But when I export to R, for example, R knows that Stata dates are stored in UTC and interprets the variable accordingly. So, what I need is dates to be displayed in CET but stored in UTC, not least because of export to other software. Still, I understand it is not possible in Stata. Many thanks!

        Comment


        • #5
          You can have it both ways in Stata over anything you display but any text such as UTC or CET would be from your code and to see what you want as CET instead of UTC there has to be addition of 1 hour.

          It's a little like a perhaps more trivial problem. If I want to see 3/7 as a percentage, I need to multiply by 100 and then it's up to me how many decimal places are shown if I don't like the default and it's up to me whether I also display the % sign or text like percent. Stata doesn't provide percentage as a display format.

          I can't comment -- as a matter of overwhelming ignorance -- on what R does or could be persuaded to do, anything you want one way or another, I guess.

          Comment


          • #6
            I have to correct myself. Stata's datetime/C is indeed said to be equivalent to UTC.

            Originally posted by Katarzyna Kopycka View Post
            So, what I need is dates to be displayed in CET but stored in UTC, not least because of export to other software.
            I don't think you need the date and time to be displayed in CET for export to other software. How would a display format that is native to Stata translate to other software, anyway? What you need is Stata's date and time, which is equivalent to UTC. How that date and time is then displayed in other software is up to the other software and cannot be controlled by Stata.

            If you want CET in Stata, you cannot do that with a display format. I see how that could be an item for the Wishlist. Personally, I think it would add more confusion than it would help; but that's me.

            Comment


            • #7
              I don't often work with different time zone data, but how I normally see these is with one variable holding the time in some reference time zone (typically UTC, say) and another variable holding the local shift to handle different time zones (which could be different on a per-observation basis).

              Comment

              Working...
              X