This should do what you want.

import time
timestring = '2010-10-10 01:10:00'
time_format = '%Y-%m-%d %H:%M:%S'
timestruct = time.strptime(timestring, time_format)
print [x for x in timestruct]


For complex date parsing I would recommend checking out the dateutil.parser
http://labix.org/python-dateutil



On Mon, May 21, 2012 at 9:47 AM, Jeremy Traurig <jeremy.trau...@gmail.com>wrote:

> Hello,
>
> Is there a module available for python to convert datetime into an
> 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
> that performs called datevec() that performs this operation. I find it
> much easier to index datetime or perform calculations on other data
> when date and time are integers. For example, i generally need to
> calculate averages, std, etc based on specific months, years, days,
> and hours. Those calculations are extremely simple when I can index an
> array of datetime integers. If there is no module to convert datetime
> to an array of integers, does anyone have an example of how i might
> index datetime using python datetime or numpy datetime64? In each
> case, I would need an array of datetime the same dimension as my data
> array.
>
> thanks -- jeremy
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Vince Spicer
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to