Issue
How can I convert a string such as:
'20190501'
To a string such as:
'2019-05-01'
Without first converting to datetime, for example:
from datetime import datetime
datetime.strptime('20190501', '%Y%m%d').strftime('%Y-%m-%d'))
The above code works, however since I'm starting and ending with a string, it seems unnecessary to use datetime
in the process. Can I convert the string directly?
Solution
if the format is always YYYYMMDD it can be converted by getting the terms in the following way:
s="YYYYMMDD"
s=s[:4]+"-"+ s[4:6]+"-"+s[6:]
Answered By - Jarred Parrett
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.