I have observations where the data was saved as csv files and now loaded into stata.
There is the 1) inclusion date =trial date and 2) echo_date= a date where we did an ultrasound of the heart (echocardiogram) on a subgroup of participants.
The trial date is not the same for all participant, it can be, but not always.
As the echo test should not be older than 1 year or 365 days from the trial_date. So I tried to change the format of the dates from strings to date, but then I am stuck.
I don't know how to extract them from each other.

generate echo_date = date(ek_echo_date, "YMD")
format %tdCCYY-NN-DD echo_date

generate trial_date = date(sp_date, "YMD")
format %tdCCYY-NN-DD trial_date

AND now to extract
drop if trial_date > 365 ... echo_date ?


My supervisor has a windows laptop while I use MAC, he has used the following commands, and it works for him

replace ek_echo_date = date("19apr2015","DMY") if sp_cpr1=="020843xxxx"
gen = (ek_echo_date-sp_date)
sort screen_echo_time


cpr is the personal id number and it is not xxxx we use in the command, it is actual numbers, but I had to hide here.
As I understand he puts one specific participant as the "start point" and then says if the date is 1 year older than that then we drop the echo, but I get "type mismatch"
Thank you very much in advance.
Best regards Lida