473,396 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1785
-----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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Nova's Taylor | last post by:
Hi folks, I am a newbie to Python and am hoping that someone can get me started on a log parser that I am trying to write. The log is an ASCII file that contains a process identifier (PID),...
4
by: Paul Beckett | last post by:
Does anyone know how to prevent an error when using DateTime.Parse? I am using it to format the display of dates in my database. However, some dates are empty and so I get an error when I try to...
4
by: Matteo | last post by:
Hy everybody. I'm not a html writer, but a sysadmin who's trying to help a user able to compile an online form with IE but not with Mozilla (Moz1.6, Ns7.1, Firefox 0.8+) due to a javascript date...
7
by: memememe | last post by:
I need to be able to parse both of these dates with the same method, and return them as a DateTime object. Is there any methods that would do this blindly or do I need to provide the format? Feb...
14
by: Jon Davis | last post by:
I have put my users through so much crap with this bug it is an absolute shame. I have a product that reads/writes RSS 2.0 documents, among other things. The RSS 2.0 spec mandates an en-US style...
0
by: Andy Fish | last post by:
Hello, I'm trying to parse dates in ISO 8601 format. I tried this: DateTime.ParseExact(inputValue, "s", CultureInfo.InvariantCulture) But this only works with one specific format. Is there...
9
by: RMC | last post by:
Hello, I'm looking for a way to parse/format a memo field within a report. The Access 2000 database (application) has an equipment table that holds a memo field. Within the report, the memo...
29
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
2
by: Jeremy | last post by:
I can't get dates to parse with any accuracy. I have a date like this, for example: Fri May 25 07:58:46 GMT 2007 I am using a SimpleDateFormat with a format string of: EEE MMM dd HH:MM:SS...
1
by: =?Utf-8?B?YXZucmFv?= | last post by:
We have a web service that gets data in xml format. In that Xml data, we parse few date fields that are in this format <data datefield="12/26/2008" timefield="16:33:45" ...> we parse it into a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.