Python 3 (Win) Is there a string var with date format YY-MM-DD how to get date?
|
3 answers
It's simple, you can use strftime:
datetime.datetime.today().strftime('%Y-%m-%d') Or you can through datetime
from datetime import * def convert_strtodate(date: string) -> datetime: return datetime.strptime(date, '%y-%m-%d') |
from datetime import datetime def convert_str2date(date: str) -> datetime: return datetime.strptime(date, '%y-%m-%d') The function accepts a YY-MM-DD format string and converts it to a datetime object.
|
import datetime today = datetime.datetime.today() print(today.strftime("%Y-%m-%d-%H.%M.%S")[8:10]) # -> 08 - This is the answer to what question? - Enikeyschik
- Enikeyschik And what I did not understand the question? explain then ... - Alexander
|
strptime()- jfs