Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75423

Re: Subtracting two dates in python

Date 2014-07-31 17:35 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: Subtracting two dates in python
References <ea9aa6cd-1fe4-420e-ac11-c3ff2be3befa@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.12472.1406824701.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 2014-07-31 17:08, eshwar080@gmail.com wrote:
> I would like to subtract two dates
>
> i.e I have entered a date into a textbox which is of type String like
> below
>
> type(waitForObject(":VWAP Calculator_LCDateTextField"), "07/24/14")
>
> I am capturing that date like below
>
> Current = (waitForObject(":VWAP Calculator_LCDateTextField").text)
>
> so, now I want to subtract the captured date with my current system
> date and get the difference in days. I tried many ways and see no
> success. Someone please help with this as soon as possible.
>
> P.S: I have python 2.4 and 2.7
>
Try the 'datetime' module:

 >>> from datetime import datetime
 >>> d = datetime.strptime("07/24/14", "%m/%d/%y")
 >>> d
datetime.datetime(2014, 7, 24, 0, 0)
 >>> diff = datetime.now() - d
 >>> diff.days
7

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Subtracting two dates in python eshwar080@gmail.com - 2014-07-31 09:08 -0700
  Re: Subtracting two dates in python John Gordon <gordon@panix.com> - 2014-07-31 16:31 +0000
  Re: Subtracting two dates in python MRAB <python@mrabarnett.plus.com> - 2014-07-31 17:35 +0100

csiph-web