Home  >  Article  >  Backend Development  >  How to convert date to week in python

How to convert date to week in python

王林
王林Original
2020-05-08 10:07:065952browse

How to convert date to week in python

This method requires the use of the datetime library.

The example code is as follows:

from datetime import datetime
week = datetime.strptime("2019-03-04","%Y-%m-%d").weekday()
print(week)

The printing result is 0.

This method will return the numbers 0-6, representing Monday to Sunday in order.

Recommended tutorial: python tutorial

The above is the detailed content of How to convert date to week in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:python calculate averageNext article:python calculate average