Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Time between 2 dates

From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: Time between 2 dates
Date   Wed, 26 Jan 2011 12:24:19 -0500

At 12:06 PM 1/26/2011, Laurie wrote:
Hi all, i would like to calculate the time between 2 dates in a data set.

I have start date like: 2010/08/02 meaning august 2nd 2010
and end date like: 2011/02/08 meaming february 2nd 2011.

I would like to know how many days are between the start date and the end date.

Presumably these values such as 2010/08/02 are of string types. First convert them to Stata dates. Assuming the variables are named startdate and enddate:
gen long startdate_n = date(startdate, "YMD")
gen long enddate_n = date(enddate, "YMD")

(The new variables are named with _n to signify "numeric", but of course, the names are arbitrary.)
You may also want...
format startdate_n enddate_n %d
(or any of several date formats) but that is optional.
Then just take the difference:
gen long daysbetween = enddate_n -startdate_n


*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index