I am using Selenium and using xpaths and I am trying to convert a date. I do have the DateTime library.
I need the date to be 1/15/23 but every time it logs it to console as 01/15/23. I am not sure why it logs it as 01 and not 1 on the month.
This is what I am using:
result_format=%m/%d/%y 12:00 AM date_format=%m/%d/%Y
It wouldn't b a big deal but I am using that date to compare against another page and it fails because of the 01.
Thanks for any help!
result_format=%m/%d/%y 12:00 AM date_format=%m/%d/%Y
Expecting it to log like this: 1/15/23 12:00 AM
CodePudding user response:
I have used the datetime library and converted datetime to str and removed 0 from prefix.
import datetime
time1 = datetime.datetime(2020, 5, 17).strftime("%m/%d/%y 12:00 AM").removeprefix("0")
print(f"time1: {time1}")
time2 = datetime.datetime(2020, 12, 17).strftime("%m/%d/%y 12:00 AM").removeprefix("0")
print(f"time2: {time2}")
Output
time1: 5/17/20 12:00 AM
time2: 12/17/20 12:00 AM
Hope this helps. Happy Coding :)