0

I am looking for a solution in Python that I can use to convert the miladi date into shamsi using mathematical calculations

I looked for this on the internet, but there was only year conversion, and I used this code:

from datetime import datetime
def persian_time():
    data = {'hour': datetime.now().hour,'min':datetime.now().minute,'year':datetime.now().year,'month':datetime.now().month,'day':datetime.now().day}
    if data['month'] <= 3 and data['day'] <= 21:
        result = 622
    elif data['month'] <= 4 and data['day'] >= 22:
        result = 621
    return data['year'] - result

I did, but it only showed the year

A student
  • 1
  • 1
  • The terms where unfamilar to me, but quick Duck Duck Going got me https://stackoverflow.com/questions/73517958/how-to-convert-persian-shamsi-date-to-gregorian-miladi-date-with-function-sc which seems reasonably straightforward to implement in Python. – tripleee Dec 26 '22 at 17:56
  • just a quick point, do something like this: `time_now = dt.datetime.now()` and then reference `time_now`. This is more efficient. – D.L Dec 26 '22 at 18:31
  • The code shown doesn't even work for the year. Try running it today and you'll get an UnboundLocalError exception – DarkKnight Dec 26 '22 at 19:11

0 Answers0