0

I am trying to figure out how to convert the current date to the 6 digit format in Julian date. So for instance, 2020-11-06 would need to be 120311. I can't figure out how to get the century number and the year before the day number. Here is the code I have so far that is printing out the day number:

def datetojulian(calendarDate):
    fmt='%Y-%m-%d'
    sdtdate = datetime.datetime.strptime(calendarDate, fmt)
    sdtdate = sdtdate.timetuple()
    jdate = sdtdate.tm_yday
    return jdate
LibertyMan
  • 47
  • 6
  • Does this answer your question? [Extract day of year and Julian day from a string date](https://stackoverflow.com/questions/13943062/extract-day-of-year-and-julian-day-from-a-string-date) – sophros Nov 06 '20 at 16:01
  • @sophros unfortunately no. So for 2020-11-06 the julian date would be 120311 for 2021-11-06 the julian date would be 121311. I need the century number then the two digit year and then the date. – LibertyMan Nov 06 '20 at 16:12
  • 1
    isn't the crux of the problem to convert the system date to Julian calendar? Formatting it in the way you did in your snippet should be enough to have it properly formatted. – sophros Nov 06 '20 at 16:21
  • The code in my snippet only gives me the day number it doesn't provide the year or century number in front of the day number. My code only provide 311 for 2020-11-06. I need 120311 for 2020-11-06. – LibertyMan Nov 06 '20 at 16:27
  • @LibertMan: could you please break down the example you gave into constituent parts? Also, shouldn't the century number be a bit larger? – sophros Nov 06 '20 at 17:45

1 Answers1

0

IF ANY ISSUE PLEASE INFORM ME

from datetime import datetime as dt
from datetime import date
now = dt.now()
yy = int(input("year : "))
mm =int(input("month : "))
_date = int(input("day : "))
julian_date = []
def convert(yy,mm,_date):
        i = str(yy)[0]+str(yy)[1]
        print(i)
        z = str(yy)[2]+str(yy)[3]
        julian_date.append(int(i)-19)
        julian_date.append(int(z))
        days = date(yy,mm,_date)-date(yy,1,1)
        julian_date.append(int(days.days))
convert(yy,mm,_date)
for i in range(len(julian_date)):
    print(julian_date[i],end="")
Naaman
  • 62
  • 3