-3

I'm plotting a graph with anaconda and it's taking a start_dt = x1[0] and end_dt = x1[29]. There are 30 values on the x axis. Right now, the date getting picked is already in Aug09 form. But I want to switch to another file where the dates are in yyyy-mm-dd form. How do I change the format of the date when it's getting passed to the state_dt and end_dt?

plt.suptitle(heading + start_dt + '-' + end_dt, size=26, fontweight='bold', va='top')
Hua Cha
  • 107
  • 1
  • 9
  • 2
    Someone took the time to make a [whole website dedicated to this very thing](http://strftime.org). – tadman Sep 06 '18 at 23:49
  • Possible duplicate of [converting string 'yyyy-mm-dd' into datetime python](https://stackoverflow.com/questions/29779155/converting-string-yyyy-mm-dd-into-datetime-python) – Alan Sep 06 '18 at 23:50
  • 2
    Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. [On topic](http://stackoverflow.com/help/on-topic), [how to ask](http://stackoverflow.com/help/how-to-ask), and [... the perfect question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) apply here. StackOverflow is not a design, coding, research, or tutorial resource. Among our expectations here are that you make a reasonable effort to research the question before posting here. – Prune Sep 06 '18 at 23:58

1 Answers1

1
date_str = '2018-08-09'
d = datetime.strptime(date_str, '%Y-%m-%d')
print(d.strftime('%b%d')

See Also the python datetime reference

Green Cloak Guy
  • 23,793
  • 4
  • 33
  • 53