<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Well, maybe. Here's the file the change and results:<br>
<blockquote># Using datetime to do date-time math on a file date-time
stamp and<br>
# the creating the new stamp<br>
from datetime import datetime, timedelta<br>
<br>
format = '%Y%m%d_%H%M%S'<br>
#d=datetime.strptime('20080321_113405', format)<br>
d = datetime.datetime(*(time.strptime('20080321_113405', format)[0:6]))<br>
print d<br>
datetime.datetime(2008, 3, 21, 11, 34, 5)<br>
d += timedelta(seconds=200)<br>
print d<br>
datetime.datetime(2008, 3, 21, 11, 37, 25)<br>
print d.strftime(format<br>
</blockquote>
Results:<br>
<blockquote>Traceback (most recent call last):<br>
File
"C:/Sandia_Meteors/Improved_Sentinel/Sentinel_Playground/Utility_Dev/debugDateTime.py",
line 7, in ?<br>
d = datetime.datetime(*(time.strptime('20080321_113405',
format)[0:6]))<br>
AttributeError: type object 'datetime.datetime' has no attribute
'datetime'<br>
<br>
</blockquote>
>From a PLEAC web:<br>
<pre class="SCREEN"><font color="#000000"><font size="+1"><span
class="comment-delimiter"># </span><span class="comment">The easiest way to convert this to a datetime seems to be;
</span>now = datetime.datetime(*time.strptime(<span class="string">"16/6/1981"</span>, <span
class="string">"%d/%m/%Y"</span>)[0:5])
<span class="comment-delimiter"># </span><span class="comment">the '*' operator unpacks the tuple, producing the argument list.</span></font></font></pre>
I tried the [0:6] and it got the same results.<br>
<br>
John Fouhy wrote:
<blockquote
cite="mid:5e58f2e40809071957h85be09ej5dfdf698530419c@mail.gmail.com"
type="cite">
<pre wrap="">2008/9/8 Wayne Watson <a class="moz-txt-link-rfc2396E" href="mailto:sierra_mtnview@sbcglobal.net"><sierra_mtnview@sbcglobal.net></a>:
</pre>
<blockquote type="cite">
<pre wrap="">I'm sure you have the essence below, but I'm not familiar with the In/ Out
notation. Apparently, I need to scoop up the In lines into a file and add
some print stmts for the In[x] d lines.
</pre>
</blockquote>
<pre wrap=""><!---->
Kent uses IPython, which is an enhanced version of the standard python
shell. That's what the In[] and Out[] bits are from.
</pre>
<blockquote type="cite">
<pre wrap="">AttributeError: type object 'datetime.datetime' has no attribute 'strptime
This attribute problem is reminiscent of my problems. IDLE? Python 2.4.x?
</pre>
</blockquote>
<pre wrap=""><!---->
Python 2.4, unfortunately. datetime.strptime only came in with Python
2.5, IIRC. The Python 2.4 version is:
d = datetime.datetime(*(time.strptime(date_string, format)[0:6]))
(i.e. that corresponds to "d = datetime.datetime.strptime(date_string, format)")
</pre>
</blockquote>
<br>
<div class="moz-signature">-- <br>
<meta content="text/html;" http-equiv="Content-Type">
<title>Signature.html</title>
<pre class="moz-signature" cols="76"> Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet
<font color="#330099">
</font> "If voting made any difference they wouldn't let us do it."
-- Mark Twain
Web Page: <<a class="moz-txt-link-abbreviated" href="http://www.speckledwithstars.net/">www.speckledwithstars.net/</a>></pre>
</div>
</body>
</html>