0

I need count days to password change in linux.

I know how to do this in python e.g:

>>> import datetime
>>> start = datetime.date(2016,1,1)
>>> end = datetime.date(2016,2,28)
>>> end-start

But my date format is:

Oct 03, 2017

How I can calculate days to a date?

Guillaume
  • 5,497
  • 3
  • 24
  • 42
Rines
  • 13
  • 2

1 Answers1

1

You can do this using strftime().
It is actually really simple:

from datetime import datetime

d1 = datetime.strptime("Jan 01, 2016", '%b %d, %Y')
d2 = datetime.strptime("Feb 28, 2016", '%b %d, %Y')
print "Delta (in days):", (d2-d1).days

And you'll get 58 as a result.

Megabeets
  • 1,378
  • 11
  • 19
  • The OP clearly states that he knows how do do it in Python. He needs to do that in 'Linux', I assume in the shell. – user2390182 Oct 05 '17 at 11:33
  • @schwobaseggl - if that's the case, the question could do with some clarification/re-wording. My interpretation is that this is a python question, working out time until a 'password change in Linux'. – MattWBP Oct 05 '17 at 11:35
  • 1
    @schwobaseggl, by looking at the tags and by reading OP's question we can assume that what bothers OP is that he doesn't know how to calculate the days using the format of date he has. I don't think he wants to do this with the shell. – Megabeets Oct 05 '17 at 11:36
  • And of course it's easy enough to run Python in a Bash command line using `python -c` – PM 2Ring Oct 05 '17 at 12:01