Display weekday of given date in Python

Display Week Day of Given Date :



Getting Started:

    * First We have to import  module such as datetime and calendar.
     
    * Create new variable to store the string date.
     * Convert the string date into datetime.datetime type using following code

              datetime.strptime(<Date>,"%d/%m/%Y") 

    * Call this function 

               calendar.day_name[my_date.weekday()]

> day_name :

           1.An array that represents the days of the week in the current locale.

>weekday :

            1.The weekday() method is used to returns the day of the week (0 is Monday) for year (1970–...), month (1–12), day (1–31).

Code :    

>>> from datetime import datetime
>>> import calendar
>>> my_date='20/12/2017'
>>> my_date=datetime.strptime(my_date,"%d/%m/%Y")
>>> calendar.day_name[my_date.weekday()]

Output:


'Wednesday'  
   

Comments

Popular posts from this blog

Uninstall ODOO module using terminal

How to Delete Menuitem-Odoo