Suggestion: AM/PM time format

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Suggestion: AM/PM time format

Richard Ristow
This would plug a long-standing hole:

A format, say AMPM11, that would display the time value

14:32:10 as  2:32:10 PM
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: AM/PM time format

Art Kendall-2
Definitely.

Art Kendall
Social Research Consultants

Richard Ristow wrote:
> This would plug a long-standing hole:
>
> A format, say AMPM11, that would display the time value
>
> 14:32:10 as  2:32:10 PM
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: AM/PM time format

Peck, Jon
There is an almost unlimited set of date and datetime formats that might occur in input or be wanted in output.  Even though SPSS has a lot of these, the current model of these formats will never extend to all the variations.  One alternative is to use a pattern representation for the parts of dates and times and let the user define the variations they want, including which parts, the order, the separators, whether to use month names - short or long in English or the local language or numbers, and variations such as 12 or 24 hour time.

While SPSS does not have this built in, if you can use Python programmability, it is available now, albeit not as conveniently as if it were a variable format.  Here is an example using a few modules downloadable from SPSS Developer Central (www.spss.com/devcentral).

The example constructs a string variable that includes an am/pm representation and decorates the dates a little in the process.  The pattern symbols in this example are
%b - abbreviated month name (in current locale language)
%d - day of  month
%Y - four-digit year
%I - hour in 12-hour notation
%M - minute
%S - seconds
%p - am/pm indicator (in current locale notation)

data list fixed /dt(datetime20).
begin data.
25-12-2007 9:15:00
1/1/2007 12:00
4/7/2000 15:00:00
end data.

begin program.
import spss, spssdata, extendedTransforms
curs = spssdata.Spssdata(indexes="dt", accessType='w')
curs.append(spssdata.vdef("ampmstring", vfmt=("A",23)))
curs.commitdict()
for case in curs:
  curs.casevalues([extendedTransforms.datetimetostr(case.dt,
   "%b %d, %Y %I:%M:%S%p")])
curs.CClose()
end program.
list ampmstring.

The list output is
mpmstring

Dec 25, 2007 09:15:00AM
Jan 01, 2007 12:00:00PM
Jul 04, 2000 03:00:00PM

Regards,
Jon Peck


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Art Kendall
Sent: Friday, September 14, 2007 6:49 AM
To: [hidden email]
Subject: Re: [SPSSX-L] Suggestion: AM/PM time format

Definitely.

Art Kendall
Social Research Consultants

Richard Ristow wrote:
> This would plug a long-standing hole:
>
> A format, say AMPM11, that would display the time value
>
> 14:32:10 as  2:32:10 PM
>
>