-2

I have a date in this format:

"2015/05/25"

How to format it like this:

"2015-05-25"
2
  • 2
    What have you tried, and what exactly is the problem with it? Even a trivial character replacement would suffice here. Commented Mar 7, 2020 at 21:37
  • 1
    Does this answer your question? Convert date format python Commented Mar 7, 2020 at 21:46

1 Answer 1

5

You can use built-in replace method for completing this task.

dateStr = "2015/05/25"
dateStr = dateStr.replace("/","-")
print(dateStr)

For more information about the replace function, you can read https://www.geeksforgeeks.org/python-string-replace/

Sign up to request clarification or add additional context in comments.

1 Comment

Would recommend using datetime module if you plan to actually use these dates

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.