470,874 Members | 1,400 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,874 developers. It's quick & easy.

parse dates

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?
May 31 '08 #1
1 1689
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[ brechmos <br******@gmail.com]
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-----
May 31 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Nova's Taylor | last post: by
4 posts views Thread by Paul Beckett | last post: by
7 posts views Thread by memememe | last post: by
reply views Thread by Andy Fish | last post: by
29 posts views Thread by gs | last post: by
2 posts views Thread by Jeremy | last post: by
1 post views Thread by =?Utf-8?B?YXZucmFv?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.