datetimelatexjulian-date

Showing percetage of the year in LaTeX


I'm trying to make a contract in LaTeX, where I express the responability of a property the year is signed. To do so, I need to calculate de percentage of the year that has already passed.

I would need to calculate the number of days in this year, the day in which we are, and then make a division, aproaching to 2 decimal digits.

Any idea more simple?

Already explained above


Solution

  • You could use pgfcalendar:

    \documentclass{article}
    
    \usepackage{tikz}
    \usepackage{pgfcalendar}
    
    \newcounter{julian}
    \newcounter{silvester}
    \newcounter{newyear}
    \newcounter{yeardays}
    \newcounter{nowdays}
    
    \makeatletter
    \pgfcalendardatetojulian{\year-\month-\day}{\c@julian} 
    \pgfcalendardatetojulian{\year-12-31}{\c@silvester} 
    \pgfcalendardatetojulian{\year-01-01}{\c@newyear} 
    \makeatother
    
    \addtocounter{newyear}{-1}
    \setcounter{yeardays}{\thesilvester}
    \addtocounter{yeardays}{-\thenewyear}
    \setcounter{nowdays}{\thejulian}
    \addtocounter{nowdays}{-\thenewyear}
    
    \begin{document}
    
    \pgfmathparse{\value{nowdays}/\value{yeardays}}
    \pgfmathprintnumber{\pgfmathresult}
    
    \end{document}