Statalist


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

Re: st: Extracting Time from Excel Sheet


From   Phil Schumm <[email protected]>
To   [email protected]
Subject   Re: st: Extracting Time from Excel Sheet
Date   Mon, 23 Feb 2009 14:16:32 -0600

On Feb 23, 2009, at 1:37 PM, [email protected] wrote:
I want to extract the time from v1
Sep/09/1998 08:42:00 PM
where v1 is
str24  %24s
However, all I can extract is
08:42:00 PM
when using substr.
I would like to extract the hours (eg 8) and PM or AM.
Any suggestions?


Assuming that v1 contains only datetime values with the same mask:


. gen foo = string(clock(v1, "MDYhms"), "%tchh_AM")

. cl

                          v1        foo
  1. Sep/09/1998 08:42:00 PM       8 PM


-- Phil

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



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index