Announcement

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

  • Converting dates

    I know there is a ton of discussion on this but having difficulty....

    want to use doc to remove his from my time stamp
    Current format of my date are: 06mar2014 14:43:15 and they are stored as str25
    when try to use dofc
    gen flag=dofc(date_var) I receive "type mismatch"

    thanks!

  • #2
    I assume that you meant hms. Check to see whether this is close to what you're seeking.

    .ÿ
    .ÿversionÿ16.1

    .ÿ
    .ÿclearÿ*

    .ÿ
    .ÿquietlyÿsetÿobsÿ1

    .ÿgenerateÿstrÿdate_varÿ=ÿ"06mar2014ÿ14:43:15"

    .ÿ
    .ÿgenerateÿintÿflag_dtÿ=ÿdate(substr(date_var,ÿ1,ÿ9),ÿ"DMY")

    .ÿformatÿ*_dtÿ%tdCY-N-D

    .ÿ
    .ÿlist,ÿnoobs

    ÿÿ+---------------------------------+
    ÿÿ|ÿÿÿÿÿÿÿÿÿÿÿdate_varÿÿÿÿÿÿflag_dtÿ|
    ÿÿ|---------------------------------|
    ÿÿ|ÿ06mar2014ÿ14:43:15ÿÿÿ2014-03-06ÿ|
    ÿÿ+---------------------------------+

    .ÿ
    .ÿexit

    endÿofÿdo-file


    .ÿ


    flag is kind of a strange name for a date.

    Comment


    • #3
      What's wrong with #1 is that dofc() is for numeric date-time variables. This would work: dofc(clock())

      Code:
      .  di %td dofc(clock("06mar2014 14:43:15", "DMY hms"))
      06mar2014
      but Joseph Coveney's method of ignoring what you don't care about is better. Note also

      Code:
      .  di %td daily(word("06mar2014 14:43:15", 1), "DMY")
      06mar2014

      Comment


      • #4
        Thanks so much! Worked perfectly

        Comment

        Working...
        X