3

I'm making a program that will print out a set of savings for tomorrow only, and i wanted to specify what date tomorrow was, which i did like this:

Tomorrow = datetime.date.today() + datetime.timedelta(days=1)

Which gives the outpu:

2016-04-11

as you can see, it does give tomorrows date like planned, except it does it in the YYYY-MM-DD format, which is my issue. is there a way to have tomorrows date printed in the DD-MM-YYYY format? Cheers

ikegami
  • 367,544
  • 15
  • 269
  • 518
Nash
  • 69
  • 1
  • 1
  • 6

2 Answers2

10

Tomorrow.strftime('%d-%m-%Y') should sort you. Hope that helped.

hd1
  • 33,938
  • 5
  • 80
  • 91
-3

Here is my answer:

dt = "9'/30'/2017  16:40:09"           # assume dt is the datetime variable
date, space, time = dt.partition(' ')  # use dt.partition to separate date and time by space
mm, slash, str = date.partition('/')   # use date.partition to separate mm and str by slash, mm is found
dd, slash, yyyy = str.partition('/')   # use str.partition to separate dd and yyyy by slash, dd and yyyy are found
new_date = dd + '/' + mm + '/' + yyyy  # set new_date in any desired format 
# new_date = 30/9/2017