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: Converting date/time string to proper date/time variable


From   Zachary Neal <[email protected]>
To   [email protected]
Subject   Re: st: Converting date/time string to proper date/time variable
Date   Fri, 30 Aug 2013 11:43:38 -0400

Thanks.  That worked perfectly.


On Fri, Aug 30, 2013 at 11:08 AM, Maarten Buis <[email protected]> wrote:
> This should solve your problem:
>
> gen double date_obs = clock(datetime_obs, "MD20Yhm")
>
> -- Maarten
>
>
> On Fri, Aug 30, 2013 at 4:58 PM, Zachary Neal <[email protected]> wrote:
>> I am attempting to convert a date/time variable imported as a string
>> (original) into a proper time variable (converted) using the following
>> syntax:
>>
>> gen date_obs = clock(datetime_obs, "MD20Yhm")
>> format date_obs %tc
>>
>> This is what I get:
>>
>> original                       converted
>> 4/4/12 10:34 AM        04apr2012 10:34:10
>> 4/4/12 10:48 AM        04apr2012 10:47:17
>> 4/5/12 10:40 AM        05apr2012 10:40:20
>> 4/5/12 10:54 AM        05apr2012 10:53:26
>> 4/10/12 10:25 AM    10apr2012 10:25:16
>> 4/11/12 10:13 AM    11apr2012 10:13:57
>> 4/11/12 10:48 AM    11apr2012 10:48:54
>> 4/16/12 9:29 AM        16apr2012 09:28:18
>> 4/16/12 9:51 AM        16apr2012 09:50:08
>> 4/16/12 10:22 AM    16apr2012 10:22:54
>>
>> As you can see, this mostly works, but seems to be randomly adding or
>> subtracting seconds from the times. I'd like the "converted" variable to
>> either not include seconds at all, or at least indicate 00 seconds in every
>> case. I'd appreciate any thoughts on what might be causing this and how to
>> fix it.
>>
>> Thanks,
>> Zachary
>>
>>
>> --
>> Zachary Neal, PhD
>> Department of Sociology
>> Michigan State University
>> [email protected]
>> http://www.msu.edu/~zpneal
>> *
>> *   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/
>
>
>
> --
> ---------------------------------
> Maarten L. Buis
> WZB
> Reichpietschufer 50
> 10785 Berlin
> Germany
>
> http://www.maartenbuis.nl
> ---------------------------------
> *
> *   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/



-- 
Zachary Neal, PhD
Department of Sociology
Michigan State University
[email protected]
http://www.msu.edu/~zpneal
*
*   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