[Tutor] Datetime Integers
vince at vinces.ca
Mon May 21 18:04:31 CEST 2012
This should do what you want.
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
On Mon, May 21, 2012 at 9:47 AM, Jeremy Traurig <jeremy.traurig at gmail.com>wrote:
> 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
> thanks -- jeremy
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor