Skip to content

Commit

Permalink
Add is_weekday
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinityyi committed Oct 28, 2020
1 parent 7b7a347 commit a985063
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions snippets/is_weekday.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: is_weekday
tags: date,beginner
---

Checks if the given date is a weekday.

- Use `datetime.datetime.weekday()` to get the day of the week as an integer.
- Check if the day of the week is less than or equal to `4`.
- Omit the second argument, `d`, to use a default value of `datetime.today()`.

```py
from datetime import datetime

def is_weekday(d = datetime.today()):
return d.weekday() <= 4
```

```py
from datetime import date

is_weekday(date(2020,10,25)) # False
is_weekday(date(2020,10,28)) # True
```

0 comments on commit a985063

Please sign in to comment.