Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Question: Year and Day of Year to date?

I have a year value and a day of year and would like to convert to a date (day/month/year).

like image 337
Mino Avatar asked Mar 11 '10 18:03

Mino


People also ask

How do I print a date in dd-mm-yyyy format in Python?

Use strftime() function of a datetime class The format codes are standard directives for mentioning in which format you want to represent datetime. For example, the %d-%m-%Y %H:%M:%S codes convert date to dd-mm-yyyy hh:mm:ss format.

How do I get the current date and year in Python?

The strfttime() function in Python is another method for obtaining the current year. The function strftime() takes a string specifying the date format as the argument. It returns the given date as a string in the provided format. We will pass "% Y" to strftime() to get the year of the date object.

How do I get the difference between two dates in Python?

Use the strptime(date_str, format) function to convert a date string into a datetime object as per the corresponding format . To get the difference between two dates, subtract date2 from date1.


1 Answers

datetime.datetime(year, 1, 1) + datetime.timedelta(days - 1) 
like image 75
Ignacio Vazquez-Abrams Avatar answered Sep 18 '22 23:09

Ignacio Vazquez-Abrams