[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gnumed-devel] date of birth - how to handle
From: |
Sebastian Hilbert |
Subject: |
Re: [Gnumed-devel] date of birth - how to handle |
Date: |
Mon, 5 Jul 2010 15:07:33 +0200 |
User-agent: |
KMail/1.13.3 (Linux/2.6.33-6-desktop; KDE/4.4.3; i686; ; ) |
Am Montag 05 Juli 2010, 13:26:27 schrieb Karsten Hilbert:
> On Mon, Jul 05, 2010 at 01:07:02PM +0200, Hilbert, Sebastian wrote:
> > I am in the process of writing the dob of a patient to a XML file.
> > gmCurrentPatient returns a datetime object. Different from a database
> > backend I cannot store the object in a XML file. I therefore convert it
> > with
> >
> > pat['dob'].strftime("%x"). This works and puts out a locale formated
> > string representation. I wonder if there is a way to determine the
> > format datetime has used in this very case (DDMMYYYY or MMDDYY) ?
>
> Have a look at the Python docs for the locale module.
> Excerpt:
>
> locale.D_T_FMT¶ Get a string that can be used as a format string
> for strftime() to represent time and date in a locale-specific way.
> locale.D_FMT¶ Get a string that can be used as a format string for
> strftime() to represent a date in a locale-specific way. locale.T_FMT¶
> Get a string that can be used as a format string for strftime() to
> represent a time in a locale-specific way. locale.T_FMT_AMPM¶ Get a
> format string for strftime() to represent time in the am/pm format.
>
> I would NOT suggest to rely on that, though. It isn't
> available cross-platform either.
>
> Decide on a format and use that. See the ISO8601 docs.
>
> > When reading in the XML files I need to convert the string representation
> > into a date (e.g. for examination date).
> >
> > Which is the best format for storage and reconverting it into a datetime
> > object ?
>
> Some form of ISO8601.
>
> > I would like to store and read the format used from the XML tag's
> > property. How do I get the format used ? I would like to avoid
> > hardcoding the format.
>
> You are better off doing so.
datetime.isoformat() works nicely
Sebastian