Bookmark and Share

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


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

Re: st: Coverting variable to date and time


From   Phil Clayton <[email protected]>
To   [email protected]
Subject   Re: st: Coverting variable to date and time
Date   Fri, 24 May 2013 19:49:15 +1000

You can convert the string to a Stata "datetime" date using the clock() function:
gen double datetime=clock(yourstring, "YMDhms")

Then you can extract the date using the dofc() function, the hour using the hh() function, minutes mm() and seconds ss().

See -help datetime-.

Phil

On 24/05/2013, at 7:35 PM, Neophytos Stylianou <[email protected]> wrote:

> Hello,
> 
> I am using Stata 12.1 and I have a variable containing date and time.
> 
> The problem is that it is a string variable and it contains both date and time within it.
> 
> I want to split them into date variable and time variable but also have the opportunity to have a date time combined variable.
> 
> Example of what the variable contains : 
> 
> 2005-02-19 09:38:00.000
> 2005-02-19 09:46:00.000
> 
> I want a variable of date i.e 19/02/2005 and time 09:38:00
> 
> I would do it manually if it was a small number of records but there are more than 1.3million rows
> 
> I know that I can combine the date and time variables which will be created using
> gen double datetime = date*24*60*60*1000 + time
> format datetime %tcNN/DD/CCYY_HH:MM:SS
> 
> Thanks for your help,
> Neo
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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