manipulating_dates_in_python
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
manipulating_dates_in_python [2023/12/02 17:07] – [iterate over a range of dates] raju | manipulating_dates_in_python [2024/02/06 05:22] (current) – raju | ||
---|---|---|---|
Line 6: | Line 6: | ||
===== Dummy ===== | ===== Dummy ===== | ||
+ | ==== date in isoformat ==== | ||
+ | |||
+ | < | ||
+ | from datetime import date | ||
+ | today = date.today().isoformat() | ||
+ | print(type(today)) | ||
+ | print(today) | ||
+ | |||
+ | <class ' | ||
+ | 2023-09-18 | ||
+ | </ | ||
+ | |||
+ | It also works on datetime objects and will give the time in ISO 8601 format. | ||
+ | < | ||
+ | from datetime import datetime | ||
+ | now = datetime.today().isoformat() | ||
+ | print(type(now)) | ||
+ | print(now) | ||
+ | |||
+ | <class ' | ||
+ | 2023-09-18T13: | ||
+ | </ | ||
+ | |||
+ | Ref:- https:// | ||
==== extract date from datetime ==== | ==== extract date from datetime ==== | ||
Line 61: | Line 85: | ||
[2021, 8, 14] | [2021, 8, 14] | ||
</ | </ | ||
- | |||
- | ==== date in isoformat ==== | ||
- | |||
- | < | ||
- | from datetime import date | ||
- | today = date.today().isoformat() | ||
- | print(type(today)) | ||
- | print(today) | ||
- | |||
- | <class ' | ||
- | 2023-09-18 | ||
- | </ | ||
- | |||
- | It also works on datetime objects and will give the time in ISO 8601 format. | ||
- | < | ||
- | from datetime import datetime | ||
- | now = datetime.today().isoformat() | ||
- | print(type(now)) | ||
- | print(now) | ||
- | |||
- | <class ' | ||
- | 2023-09-18T13: | ||
- | </ | ||
- | |||
- | Ref:- https:// | ||
==== iterate over a range of dates ==== | ==== iterate over a range of dates ==== | ||
Line 185: | Line 184: | ||
December | December | ||
</ | </ | ||
+ |
manipulating_dates_in_python.txt · Last modified: 2024/02/06 05:22 by raju