
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I get the current week using Python?
YOu can use the isocalender function from the datetime module to get the current week. Create the object of the date first, then call isocalender() on this object. This returns a 3-tuple of Year, Week number and Day of Week.
Example
import datetime my_date = datetime.date.today() # if date is 01/01/2018 year, week_num, day_of_week = my_date.isocalendar() print("Week #" + str(week_num) + " of year " + str(year))
Output
This will give the output −
Week #1 of year 2018
- Related Questions & Answers
- How can I get the current Android SDK version programmatically using Kotlin?
- How can I get the current screen orientation in Android?
- How can I get the current Android SDK version programmatically?
- How can I get the current time and date in Kotlin?
- How to get first day of the week using Python?
- How can I get the current contents of an element in webdriver?
- C# Program to get current day of week
- How to query MySQL on the current week?
- How do I get the current date in JavaScript?
- How can I apply an offset on the current time in Python?
- Java Program to get date for all the days of the current week
- How do I get current URL in Selenium Webdriver 2 Python?
- How do I get the current time zone of MySQL?
- How can I get a file's permission mask using Python?
- How can we get the current language selected in the Android device using Kotlin?
Advertisements