[Tutor] Datetime Integers

Walter Prins wprins at gmail.com
Mon May 21 18:09:55 CEST 2012


Hi Jeremy,

On 21 May 2012 16:47, Jeremy Traurig <jeremy.traurig at gmail.com> wrote:

> Is there a module available for python to convert datetime into an
>
I presume you mean, "convert a datetime *string* into an array of integers"?

array of integers. For example, I have date where the first column is
> a datetime string (i.e. '2010-10-10 01:10:00') and I would like to
> convert that into an array with 5 columns corresponding to the integer
> values of Year,Month,Day,Hour,Minute. There is a function in Matlab
>
Yes, Python datetime objects support that directly.  If d is a Python
datetime, then d.year gives you the year, d.month gives you the month
etc.   See here:  http://docs.python.org/library/datetime.html  Also see
8.1.7 regarding converting to and from datetime strings.

Walter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120521/bbbec1ec/attachment.html>


More information about the Tutor mailing list