Announcement

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

  • another questions about converting HRF datetime to SIF

    I have read "help datetime", but am still having trouble converting a string datetime variable into a stata variable. My input is formatted like "2007-12-19 00:19:33". After I format the output, I get years that were input as "2007" rendering as "207" in the formatted output. Any suggestions? Here is what I do

    Code:
    gen double userregdate = clock(userregtime, "YMDhms")
    format userregdate  %tccy/N/d
    list userregtime userregdate  in 1/10
    
         +----------------------------------+
         |         userregtime   userregd~e |
         |----------------------------------|
      1. | 2007-12-19 00:19:33    207/12/19 |
      2. | 2007-10-29 14:50:22    207/10/29 |
    The same output occurs when I use the "date()" rather than the "clock()" function.
    Code:
    . gen double userregdate = date(userregtime, "YMDhms")
    . format userregdate  %tdcy/N/d
    . list userregtime userregdate  in 1/10
    
         +----------------------------------+
         |         userregtime   userregd~e |
         |----------------------------------|
      1. | 2007-12-19 00:19:33    207/12/19 |
      2. | 2007-10-29 14:50:22    207/10/29 |
         +----------------------------------+
    The conversion to stata date works, since format userregdate %td gives correct output

    Code:
        +---------------------------------+
         |         userregtime   userre~te |
         |---------------------------------|
      1. | 2007-12-19 00:19:33   19dec2007 |
      2. | 2007-10-29 14:50:22   29oct2007 |
    but using variation of the C, c, CCir cc as listed in the details portion of https://www.stata.com/manuals13/ddat...layformats.pdf doesn't give me the expected output.

    bob kraut

  • #2
    Code:
    . di %tc clock("2007-12-19 00:19:33", "YMDhms")
    19dec2007 00:19:33
    
    . di %tcCY-d-N clock("2007-12-19 00:19:33", "YMDhms")
    2007-19-12
    
    . di %tcCY/N/d clock("2007-12-19 00:19:33", "YMDhms")
    2007/12/19

    Comment

    Working...
    X