Announcement

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

  • combining 2 separate variables for date and time into one variable

    Hi all

    I have two separate variables for date (DD/MM/YYYY) and time (hh:mm) and I would like to combine them into one variable (DD/MM/YYYY hh:mm).

    Does anyone please have the code for this? I've had a look in the datetime help file but still can't figure it out.

    Any help appreciated, thanks in advance!

  • #2
    Are these variables both strings? If so:

    Code:
    clear
    input str29 (date time)
    "17/04/2024" "09:57"
    end
    
    gen double wanted= clock(date+time, "DMYhm")
    format wanted %tc
    Res.:

    Code:
    . l
    
         +-----------------------------------------+
         |       date    time               wanted |
         |-----------------------------------------|
      1. | 17/04/2024   09:57   17apr2024 09:57:00 |
         +-----------------------------------------+

    Comment

    Working...
    X