User Tools

Site Tools


manipulating_dates_in_python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
manipulating_dates_in_python [2023/12/13 23:45] – [print the names of months in a year] rajumanipulating_dates_in_python [2024/02/06 05:22] (current) raju
Line 6: Line 6:
 ===== Dummy ===== ===== Dummy =====
  
 +==== date in isoformat ====
 +
 +<code>
 +from datetime import date
 +today = date.today().isoformat()
 +print(type(today))
 +print(today)
 +
 +<class 'str'>
 +2023-09-18
 +</code>
 +
 +It also works on datetime objects and will give the time in ISO 8601 format.
 +<code>
 +from datetime import datetime
 +now = datetime.today().isoformat()
 +print(type(now))
 +print(now)
 +
 +<class 'str'>
 +2023-09-18T13:55:17.214513
 +</code>
 +
 +Ref:- https://stackoverflow.com/questions/32490629/getting-todays-date-in-yyyy-mm-dd-in-python
  
 ==== extract date from datetime ==== ==== extract date from datetime ====
Line 61: Line 85:
 [2021, 8, 14] [2021, 8, 14]
 </code> </code>
- 
-==== date in isoformat ==== 
- 
-<code> 
-from datetime import date 
-today = date.today().isoformat() 
-print(type(today)) 
-print(today) 
- 
-<class 'str'> 
-2023-09-18 
-</code> 
- 
-It also works on datetime objects and will give the time in ISO 8601 format. 
-<code> 
-from datetime import datetime 
-now = datetime.today().isoformat() 
-print(type(now)) 
-print(now) 
- 
-<class 'str'> 
-2023-09-18T13:55:17.214513 
-</code> 
- 
-Ref:- https://stackoverflow.com/questions/32490629/getting-todays-date-in-yyyy-mm-dd-in-python 
  
 ==== iterate over a range of dates ==== ==== iterate over a range of dates ====
manipulating_dates_in_python.txt · Last modified: 2024/02/06 05:22 by raju