[Tutor] Date subtraction

alan.gauld@bt.com alan.gauld@bt.com
Fri, 6 Apr 2001 11:54:45 +0100


------_=_NextPart_001_01C0BE87.FE0385C0
Content-type: text/plain; charset="iso-8859-1"

Look at the time module.
 
>  I want to have a user enter a date in format  
>  dd/mm/YYYY like 06/04/2001 and another date  
>  in the same format like 22/04/2001 
 
Here is some pseudo code:
 
#------------- 
start = raw_inpu('start date dd/mm/yyyy ')
end = raw_input('end date dd/mm/yyyy ')
startTime = convert time string to time value
endTime = convert time string to time value
 
times = []
timestrings = []
newTime = startTime
while newTime < end:
    times.append(newTime)
    newTime = newTime + 1 day
 
for t in times:
   str = convert t to time string
   timestrings.append(str)
 
#--------------
The time module contains all the bits you need to do the conversions.
 
HTH,
 
Alan G

 


------_=_NextPart_001_01C0BE87.FE0385C0
Content-type: text/html; charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>Date subtraction</TITLE>

<META content="MSHTML 5.00.3013.2600" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=110525010-06042001>Look 
at the time module.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=110525010-06042001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff><FONT face=Arial><TT><SPAN 
class=110525010-06042001>&gt; &nbsp;</SPAN>I want to have a user enter a date in 
format&nbsp;<SPAN 
class=110525010-06042001>&nbsp;</SPAN></TT></FONT></FONT></DIV>
<DIV><FONT color=#0000ff><FONT face=Arial><TT><SPAN 
class=110525010-06042001>&gt; &nbsp;</SPAN>dd/mm/YYYY like 06/04/2001</TT> 
<TT>and another date&nbsp;<SPAN 
class=110525010-06042001>&nbsp;</SPAN></TT></FONT></FONT></DIV>
<DIV><FONT color=#0000ff><FONT face=Arial><TT><SPAN 
class=110525010-06042001>&gt; &nbsp;</SPAN>in the same format like 
22/04/2001</TT>&nbsp;<BR><FONT size=2><SPAN 
class=110525010-06042001>&nbsp;</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT color=#0000ff><SPAN class=110525010-06042001><FONT face="Courier New" 
size=2>Here is some pseudo code:</FONT></SPAN></FONT></DIV>
<DIV><FONT color=#0000ff><SPAN 
class=110525010-06042001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New"><FONT color=#0000ff size=2><SPAN 
class=110525010-06042001>#-------------&nbsp;</SPAN></FONT></FONT></DIV><TT><SPAN 
class=110525010-06042001><FONT color=#0000ff></FONT></SPAN></TT>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN class=110525010-06042001>start = 
raw_inpu('start date dd/mm/yyyy ')</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN class=110525010-06042001>end = 
raw_input('end date dd/mm/yyyy ')</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN class=110525010-06042001>startTime 
= convert time string to time value</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN class=110525010-06042001>endTime = 
convert time string to time value</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN 
class=110525010-06042001></SPAN></TT></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN class=110525010-06042001>times = 
[]</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN 
class=110525010-06042001>timestrings = []</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN class=110525010-06042001>newTime = 
startTime</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN class=110525010-06042001>while 
newTime &lt; end:</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN 
class=110525010-06042001>&nbsp;&nbsp;&nbsp; 
times.append(newTime)</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN 
class=110525010-06042001>&nbsp;&nbsp;&nbsp; newTime = newTime + 1 
day</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN 
class=110525010-06042001></SPAN></TT></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN class=110525010-06042001>for t in 
times:</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN 
class=110525010-06042001>&nbsp;&nbsp; str = convert t to time 
string</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN 
class=110525010-06042001>&nbsp;&nbsp; 
timestrings.append(str)</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN 
class=110525010-06042001></SPAN></TT></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN 
class=110525010-06042001>#--------------</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN class=110525010-06042001>The time 
module contains all the bits you need to do the 
conversions.</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN 
class=110525010-06042001></SPAN></TT></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN 
class=110525010-06042001>HTH,</SPAN></TT></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN 
class=110525010-06042001></SPAN></TT></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial><TT><SPAN class=110525010-06042001>Alan 
G</SPAN></TT></FONT></DIV>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <P>&nbsp;</P></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C0BE87.FE0385C0--