Reputation: 61
My variable DateBecame
looks like this:
19550101
It is of long
type and the format is %10.0g
. So YMD
format.
I also have another variable DateLeft
:
19961001
This is also of long
type and format %10.0g
.
How can I calculate the duration between the two dates?
Upvotes: 0
Views: 3023
Reputation:
The following works for me:
clear
input long(date1 date2)
19550101 19961001
end
generate diff = daily(string(date1, "%10.0g"), "YMD") - ///
daily(string(date2, "%10.0g"), "YMD")
list
+---------------------------------+
| date1 date2 diff |
|---------------------------------|
1. | 19550101 19961001 -15249 |
+---------------------------------+
Note that variables of long
type are generally not ideal for this kind of calculations.
Type help datetime
from Stata's command prompt for more information on working with dates.
Upvotes: 1