Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to put in my resume

N years experience in Java

where N would be generated based on the date provided in the LaTeX file.

Preferably in rounded years, i.e. If the beginning date was 2012-06-04 and the output was generated on 2014-04-04, then the N would be 2.

share|improve this question

1 Answer 1

up vote 7 down vote accepted

A macro using the function defined in my answer to Day of the year

\documentclass{article}

\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\roundyears}{mmm}
 {% #1 = year, #2 = month, #3 = day (beginning of experience
  \fp_eval:n
   {
    floor (
     ( \juliandate_calc:nnnn { \day } { \month } { \year } { \use:n }
      -
      \juliandate_calc:nnnn { #3 } { #2 } { #1 } { \use:n } ) / 365
    )
   }
 }

\cs_new:Npn \juliandate_calc:nnnn #1 #2 #3 #4 % #1 = day, #2 = month, #3 = year, #4 = what to do
 {
  #4
   {
    \int_eval:n
     {
      #1 +
      \int_div_truncate:nn
       {
        153 * (#2 + 12 * \int_div_truncate:nn { 14 - #2 } { 12 } - 3) + 2
       }
       { 5 } +
      365 * (#3 + 4800 - \int_div_truncate:nn { 14 - #2 } { 12 } ) +
      \int_div_truncate:nn { #3 + 4800 - \int_div_truncate:nn { 14 - #2 } { 12 } } { 4 } -
      \int_div_truncate:nn { #3 + 4800 - \int_div_truncate:nn { 14 - #2 } { 12 } } { 100 } +
      \int_div_truncate:nn { #3 + 4800 - \int_div_truncate:nn { 14 - #2 } { 12 } } { 400 } -
      32045
     }
   }
 }

\ExplSyntaxOff

\begin{document}

\roundyears{2011}{05}{06}

\roundyears{2012}{05}{03}

\roundyears{2012}{07}{12}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.