Re: parse dates



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

[ brechmos <brechmos@xxxxxxxxx> ]

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-----
.



Relevant Pages

  • Re: [Date] Converting dd/mm/yyyy to YYYY-MM-DD?
    ... over here, so strtotime() is wrong. ... It does somewhat annoy me that PHP will assume 01/02/03 to be 2 Jan 2003, ... when the vast majority of the world's population will take it to be either ... Australia and NZ all use little-endian DMY dates: ...
    (comp.lang.php)
  • Re: i love strtotime but it is no use in New Zealand
    ... windandwaves wrote: ... I love the strtotime function, because I can make a date field in a form ... PHP purposes, which is easy once you know what field is what. ... # Returns a timestamp from a string based on the given format and default ...
    (comp.lang.php)
  • Re: [PHP] Re: strtotime
    ... Cette liste est une liste anglaise, reformulent svp votre question en ... PHP General Mailing List ... Probably because strtotime returns null so date thinks that null is equivalent to 0 or something like that AFAIK. ...
    (php.general)
  • Re: [PHP] dst and strtotime
    ... Subject: [PHP] dst and strtotime ... www.dwsasia.com - company web site ...
    (php.general)