-3

I want the number of days from Monday. Like on Thursday it should return 4. Below is the code, its not giving relevant result

import datetime
dt = datetime.datetime.now() 
dt.weekday()
Supriya M
  • 14
  • 9
  • Does this answer your question? [How to calculate number of days between two given dates?](https://stackoverflow.com/questions/151199/how-to-calculate-number-of-days-between-two-given-dates) – Maurice Meyer Nov 11 '20 at 13:34
  • https://docs.python.org/2/library/datetime.html#datetime.date.weekday – Simon Danninger Nov 11 '20 at 13:35

3 Answers3

-1

Weekday returns day number in format Monday -> 0, Tuesday -> 1 etc. etc., if you want it to start from one, just add 1 to the result.

Nastor
  • 638
  • 4
  • 15
-1

According to the documentation isoweekday should do the trick

import datetime
dt = datetime.datetime.now() 
dt.isoweekday()

returns 4 on Thursday

Anton van der Wel
  • 451
  • 1
  • 6
  • 20
-1

You can calculate it normally and add one to the answer:

import datetime
dt = datetime.datetime.now()
print(dt.weekday()+1)

or use the standard (official) method:

import datetime
dt = datetime.datetime.now() 
dt.isoweekday()
khushi
  • 365
  • 1
  • 4
  • 17