Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use dateutil.relativedelta in Python 3.x?

Hello I am trying to use relativedelta from the dateutil module.

I want to do what is mentioned here, add some months to a given datetime object.

But I'm trying to use Python 3 for this and I am getting the following error:

Traceback (most recent call last):
  File "bin/controller.py", line 2, in <module>
    from dateutil.relativedelta import relativedelta
ImportError: No module named 'dateutil'

I then read that dateutil is now part of Python 3 but how do I import it? import dateutil does not seem to work:

Traceback (most recent call last):
  File "bin/controller.py", line 3, in <module>
    import dateutil
ImportError: No module named 'dateutil'

I am using a virtualenv so I would like to install it with pip.

like image 991
aairey Avatar asked Aug 05 '16 14:08

aairey


People also ask

What is dateutil Relativedelta Python?

The relativedelta type is designed to be applied to an existing datetime and can replace specific components of that datetime, or represents an interval of time. It is based on the specification of the excellent work done by M. -A. Lemburg in his mx. DateTime extension.

Is dateutil included in Python 3?

Python 2. x has an extraordinary function called dateutil. parser which transforms an ISO8601 arranged date into a python DateTime value. It's absent in Python 3.

Is dateutil a standard Python library?

The dateutil module specializes in providing an extension of features to the existing datetime module, and as such, the installation of the datetime module is a prerequisite. However, since it's a part of the Python standard library, there's nothing to worry about.


1 Answers

It seems you have to pip-install it like this and it works :

pip install python-dateutil
like image 54
acknowledge Avatar answered Sep 28 '22 21:09

acknowledge