# The year counter is here [closed]

Create a program that, given an integer N, outputs the number of years we have to get to N A.D. or how many years it has been since N A.D, as a string or int. For example, given 2014, the program should output 5 as it has been that many years since 2014. Input of the year in which you run the program should result in 0.

Treat the input "0" however you like: as its own year, as 1 A.D. or as 1 B.C. This means that you can pretend there IS a year zero and have all BC years be off by one.

Negative integers (integers with - in front of them) are treated as years B.C. For example inputting -2 would result in the program telling how many years it has been since 2 B.C.

Treat improper inputs (inputs that don't only use numbers and the dash as characters (abcd), or use the dash by itself or use it wrongly (e.g. 6-)) however you want, error or exit or something else.

The winning program is the program with the shortest code that does all of this. Have fun.

• Am I dumb or has it been 5 years since 2014? – HyperNeutrino Jun 13 '19 at 14:07
• @HyperNeutrino it has – Luis felipe De jesus Munoz Jun 13 '19 at 14:08
• So an input of -1 should result in an output of 2019 this year? – Neil Jun 13 '19 at 14:25
• @HyperNeutrino maybe the thinking is that only 4 full calendar years have passed since the end of 2014. So what is the output meant to be for 2009?.. – Jonathan Allan Jun 13 '19 at 14:28
• @JonathanAllan Hm. Well, OP posted and probably left, so hopefully they clarify, because otherwise I'm tempted to CV this because there are like three reasonable interpretations plus the answer of "OP forgot it was 2019" – HyperNeutrino Jun 13 '19 at 14:33

# 05AB1E, 3 bytes

žgα


Try it online!

Explanation

  α   # absolute difference between
# implicit input
žg    # and current year


# Java 8, 46 bytes

n->(n-=java.time.Year.now().getValue())<0?-n:n


Try it online.

Or alternatively:

n->Math.abs(n-java.time.Year.now().getValue())


Try it online.

# Japt, 3 bytes

aKi


Try it

aKi     :Implicit input of year
a       :Absolute difference with
K      :  Date
i     :  Get year

• lol, we posted the same answer at the same time. I deleted mine tho, i had another in php anyway – Luis felipe De jesus Munoz Jun 13 '19 at 14:14
• @LuisfelipeDejesusMunoz - technically, you got there first ... by 8 seconds! No need to delete either of them, though; it happens sometimes. – Shaggy Jun 13 '19 at 14:18

# Pyth, 4 bytes

a.d3


Try it online!

Explanation:

a.d3Q - full program. implicit Q added.
a     - absolute difference of
.d3  - current year and
Q - implicit input


# C# (Visual C# Interactive Compiler) with /u:System.Math and /u:System.DateTime flags, 32 18 bytes

n=>Abs(Now.Year-n)


Try it online.

# PHP, 22 bytes

<?=date('Y')-\$argv[1];


Try it online!

# Python 3, 66 bytes

from datetime import*
print(abs(int(input())-datetime.now().year))


Try it online!

Gives 5 for 2014 because it's 2019, not 2018.

# Red, 30 bytes

func[y][absolute y - now/year]


Try it online!

# JavaScript (Node.js), 33 bytes

a=>Math.abs(Date().split [3]-a)


Try it online!

-6 bytes thanks to Luis felipe De jesus Munoz

• @LuisfelipeDejesusMunoz Oh thanks! – HyperNeutrino Jun 13 '19 at 15:57

# C++ (gcc), 131 127 bytes

#include<ctime>
#include<cstdio>
int main(){long y,t=time(0);scanf("%d",&y);y-=gmtime(&t)->tm_year+1900;printf("%d",y<0?-y:y);}


Try it online!

• Thanx for the hint, found an even better solution :) – movatica Jun 14 '19 at 22:17
• 118 bytes – ceilingcat Dec 10 '19 at 3:06