Announcement

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

  • Having problem changing this date format (dd-mmm-yy) to ‘ddmmmyyyy’

    Greetings,
    I would need help to change this date format (dd-mmm-yy) to ‘ddmmmyyyy’
    e.g 10-Aug-15 to 10Aug2015
    4-Dec-16 to 04Dec2016

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float var1
    20310
    20792
    end
    format %tddd-Mon-YY var1
    
    list
    
    format var1 %tdDDMonCCYY
    
    list
    Note: I assume your date variable is already a Stata numeric internal format date variable and the issue is just the display format. If you are working from a string variable, then use the -daily()- function to get the numeric equivalent, and then apply the display format. If for some reason you actually need a string variable that looks like 04Dec2016, then apply -tostring- with options -format(%tdDDMonCCYY)- and -force-

    For future reference, when you need to find out what the code is for a particular date time display format, you can get that by looking at -help datetime_display_formats-.

    Comment


    • #3
      Sorry for my comment on already answered post: posted in error as the post has been answered as above while I was typing

      Steps: Convert to stata internal format for date string in your data-- then format it as in the code below

      clear
      input str20 date
      "10-Aug-15"
      end
      g date_sif=date(date, "DMY", 2015)
      format date_sif %tddmCY
      Last edited by ram singh; 07 Aug 2017, 11:38.

      Comment


      • #4
        Many thanks. very helpful

        Comment

        Working...
        X