0

I'm quite lost and I'm in need of trying to format some code so it ends up having dashes in the date. I can get 3, 12, 28 but I can't get 3-12-28. I am a super new beginner so I'm quite lost at the moment.

    year = 3
    month = 12
    day = 28
    print(date)

3 Answers3

2

Try

print("{0}-{1}-{2}".format(year,month,day))
emilaz
  • 1,722
  • 1
  • 15
  • 31
1

You could use datetime to format the result

import datetime

year = 3
month = 12
day = 28

dt = (datetime.date(year, month, day))
print(dt)

the result will be 0003-12-28

if you want more examples of datetime you could take a look at https://docs.python.org/2/library/datetime.html#

Thijs
  • 26
  • 4
0

As you say you are new to python you can concatenate the strings together.

year = 3
month = 12
day = 28
date = year + "-" + month + "-" + day
print(date)

Alternatively you can use format to set the variables in your required format.

print(f"{year}-{month}-{day}")

Another method is to use datetime if you are using todays date

import datetime

today = datetime.date.today()
print(today)
CodeCupboard
  • 1,507
  • 3
  • 17
  • 26