Announcement

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

  • date format

    Good evening to everyone,
    I have a variable generated by the command gen Hdate = clock(StartDate, "DMY hms") displayed as 15jan2022 09:06:44.

    I would like to create a new variable by using the information in that date format (DMY hms) : eg newvar == 1 on 15 jan from 9 to 10 ; newvar == 2 on 15 jan from 10 to 11 ; newvar == 3 on 15 jan from 11 to 12.

    Someone could kindly suggest to me how to handle this date format?

    Many thanks in advance for your time
    Last edited by Chiara Tasselli; 17 Nov 2022, 09:43.

  • #2
    Defined precisely how?

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Defined precisely how?
      Sorry,
      I accidentally sent it before finishing the message.
      I have edit it

      Comment


      • #4
        Originally posted by Nick Cox View Post
        Defined precisely how?
        Sorry,
        I accidentally sent it before finishing the message.
        I edited it

        Comment


        • #5
          First off, you need

          Code:
          gen double Hdate = clock(StartDate, "DMY hms")
          -- as is explained many times within the help for datetime.

          The experiment

          Code:
          . di   hh(clock("15jan2022 09:06:44", "DMY hms"))
          9
          implies to me that you seek

          Code:
          gen wanted = hh(Hdate) - 8

          Comment

          Working...
          X