Announcement

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

  • UTC date format

    How can i format a date like this "Wed Feb 20 12:29:11 UTC 2013" so that it can be in the correct date format like "YMDhm". The variable is currenntly str28 and format %28s
    Last edited by Cyrus Muriithi; 25 Feb 2016, 00:21.

  • #2
    All documented, under help datetime translation

    Code:
    . di %tc clock("Wed Feb 20 12:29:11 UTC 2013", "# MD hms # Y")
    20feb2013 12:29:11
    
    
    * hence 
    gen double whatiwant = clock(whatihave, "# MD hms # Y")

    Comment


    • #3
      Thank, its working. I just added

      gen double vcs002_n = clock(vcs002, "# MD hms # Y")
      format vcs002_n %tc

      So that i can format the entire records for that variable

      Comment


      • #4
        Indeed; that way round you do need to specify a format.

        Here's another way to do it:

        Code:
        . clear
        
        . set obs 1
        number of observations (_N) was 0, now 1
        
        . gen mystr = "Wed Feb 20 12:29:11 UTC 2013"
        
        . ssc inst numdate 
        
        . help numdate 
        
        . numdate clock mytime = mystr, pattern("# M D hms # Y")
        
        . l
        
             +---------------------------------------------------+
             |                        mystr               mytime |
             |---------------------------------------------------|
          1. | Wed Feb 20 12:29:11 UTC 2013   20feb2013 12:29:11 |
             +---------------------------------------------------+
        See also http://www.statalist.org/forums/foru...date-variables

        Comment


        • #5
          Thank you, so much.

          Comment

          Working...
          X