Home > Mobile >  Determine a date starting from two integer numbers
Determine a date starting from two integer numbers

Time:11-03

Determine a date (as day, month, year) starting from two integer numbers that represent the year and the number of the day in that year.

i'm new to coding and I don't know where to start even.

CodePudding user response:

If I understand correctly you can use Python datetime module to do what you need:

from datetime import datetime
print(datetime.strptime("2004-68", "%Y-%j").strftime("%d.%m.%Y"))

Result:

08.03.2004

CodePudding user response:

You can start with creating algorithm in your head, or on paper. Then you can translate it to python code.

or

you can read documentation about datetime lib in python and try to combine functions to you desired output. https://docs.python.org/3/library/datetime.html

For example:

from datetime import datetime, timedelta
year = 2004
days = 68
date = datetime(year, 1, 1)   timedelta(days=days-1)
# days-1 is needed because we already start with first day in year
print(date)
# 2004-03-08 00:00:00

CodePudding user response:

year=int(input("year="))
days=int(input("number of days="))
day=int
month = days/28   1
m = int(month)
if ((year % 400 == 0) or
        (year % 100 != 0) and
        (year % 4 == 0)) :
    day = days % 30
else:
    day = days % 30   1

print(day,".", m, ".",year)   

is this any good? or more preciseley is it corect? like i need this more basic aproach to the problem

  • Related