Dear Statalists,

I am trying to do a subtraction between dates to come up with the time interval between a start date and an end date. However, I am having trouble extracting dates from both the starting and ending dates.

The ending dates are stored as DD/MM/YYYY format in the variable called MaturityDate. However, this variable is in long format, which I am not sure if it will fit in the future subtraction. I also tried to convert it into strings, the output was just a number which really confused me.

The starting dates are not explicitly provided in the dataset but are incorporated in the file name. The file names are stored in a variable in the form of ALTG0BC-12311997.xlsx , which is string type data. When I tried to use the command substr to extract the date from the file with the command
Code:
gen enddate=substr( filename,9,16)
The output variable enddate turned out to be 12311997.xlsx, from which I want to take the .xlsx away.

Could you help me with these two problems?