Skip to content

Commit 2d425ac

Browse files
authored
[Edit] Python Dates: datetime.date()
* Updated dates for Python added definitions and codeblocks * Minor changes ---------
1 parent 611bd51 commit 2d425ac

File tree

1 file changed

+29
-1
lines changed
  • content/python/concepts/dates/terms/date

1 file changed

+29
-1
lines changed

content/python/concepts/dates/terms/date/date.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,37 @@ All parameters passed to the `datetime.date()` method in the snippet above are r
2828
| `MM` | The month expressed in one or two digits. | 1 - 12 |
2929
| `DD` | The day of the month expressed in one or two digits. | 1 - number of days in a given month and year |
3030

31+
## Example
32+
33+
Here's a detailed example of using `datetime.date()` to create a date object and access its components:
34+
35+
```py
36+
import datetime
37+
38+
example_date = datetime.date(2024, 10, 15)
39+
40+
year = example_date.year
41+
month = example_date.month
42+
day = example_date.day
43+
44+
print("Complete Date:", example_date)
45+
print("Year:", year)
46+
print("Month:", month)
47+
print("Day:", day)
48+
```
49+
50+
The above code produces the following output:
51+
52+
```shell
53+
Complete Date: 2024-10-15
54+
Year: 2024
55+
Month: 10
56+
Day: 15
57+
```
58+
3159
## Codebyte Example
3260

33-
A date can be retrieved and stored in a variable as shown below:
61+
The following codebyte example shows the usage of the `datetime.date()` method:
3462

3563
```codebyte/python
3664
import datetime

0 commit comments

Comments
 (0)