parse dates

B

brechmos

Hi,

I have been using PHP the last while and in particular strtotime.
What I want to replicate is finding the second or fourth Monday of the
next month. In PHP with strtotime it is easy (strtotime("second
Monday", strtotime("next month"), but I can't find an easy way to do
it in Python. I have seen DateUtil, but it seems to be able to do
only the simpler parsing (could be wrong).

Any other ideas?
 
S

Sebastian 'lunar' Wiesner

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[ brechmos said:
Hi,

I have been using PHP the last while and in particular strtotime.
What I want to replicate is finding the second or fourth Monday of the
next month. In PHP with strtotime it is easy (strtotime("second
Monday", strtotime("next month"), but I can't find an easy way to do
it in Python. I have seen DateUtil, but it seems to be able to do
only the simpler parsing (could be wrong).

Any other ideas?

If parsing is not required, dateutil is just fine:

from datetime import datetime
from dateutil import relativedelta

# second monday
datetime.now() + relativedelta.relativedelta(day=1, weekday=relativedelta.MO(+2))

# next month
datetime.now() + relativedelta.relativedelta(months=+1)

- --
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkhBqcMACgkQn3IEGILecb7FXgCgg1X7vrP/uzTaPa5W3e2WsDFV
e5kAnizMQUDLfz07Z/d1hVehlCmoJuKl
=yi9t
-----END PGP SIGNATURE-----
 
E

Eddie Corns

brechmos said:
I have been using PHP the last while and in particular strtotime.
What I want to replicate is finding the second or fourth Monday of the
next month. In PHP with strtotime it is easy (strtotime("second
Monday", strtotime("next month"), but I can't find an easy way to do
it in Python. I have seen DateUtil, but it seems to be able to do
only the simpler parsing (could be wrong).
((2008, 7, 1, 9, 0, 0, 1, 183, -1), 1)

Eddie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,666
Latest member
selsetu

Latest Threads

Top