Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: ODBC date/time query


From   [email protected] (Kevin Turner)
To   [email protected]
Subject   st: Re: ODBC date/time query
Date   Wed, 30 Jul 2003 17:25:13 -0500

Chris <[email protected]> wrote:

>I am attempting to import data via the ODBC command.  All of the
>variables import fine except a date/time variable.  The variable is in
>the format [mm/dd/yyyy hh:mm AM] When I load the data in Stata all I get
>is the date information, not the time.  For some reason it truncates and
>assigns it the %td format.  When I query the same database in MS Access
>I get the complete date and time.  Why doesn't Stata pull all the data
>from the field when it imports?  Any suggestions?   Thanks.

There is currently no explicit time format in Stata. That may change and in 
light of that, the import of time data was left intentionally to the 
realm of SQL SELECT statements. You can use the exec() option to specify a 
SELECT statement that splits or casts the time information to either a string
or numeric. Here is a generic example:

. odbc load, exec("SELECT CAST(d AS VARCHAR(30)) FROM table") dsn(mydsn)

.. where 'd' is the timestamp variable. You could then split the date/time 
info from within Stata or use a more complicated SQL statement that does that
step for you. Furthermore, CAST is not the only SQL conversion function, just
the most popular. 

Hope this helps,

--Kevin 
[email protected]

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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