File tree 1 file changed +29
-1
lines changed
content/python/concepts/dates/terms/date
1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -28,9 +28,37 @@ All parameters passed to the `datetime.date()` method in the snippet above are r
28
28
| ` MM ` | The month expressed in one or two digits. | 1 - 12 |
29
29
| ` DD ` | The day of the month expressed in one or two digits. | 1 - number of days in a given month and year |
30
30
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
+
31
59
## Codebyte Example
32
60
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 :
34
62
35
63
``` codebyte/python
36
64
import datetime
You can’t perform that action at this time.
0 commit comments