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

st: RE: Re: ODBC date/time query

From   "Nick Cox" <>
To   <>
Subject   st: RE: Re: ODBC date/time query
Date   Thu, 31 Jul 2003 12:14:46 +0100

Chris <> 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.

Kevin Turner 

> 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. 

On the question of Stata support for time of day 
manipulations -- and in essence there is in the very 
strictest sense none as such -- 
I posted on 28 January 2003 a note on bits and 
pieces available inside and outside official Stata. I 
asked for comments on errors and omissions, but 
didn't get any. 

One motivation for the official Stata command -split- 
was to support manipulations of this kind. 


*   For searches and help try:

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