24
\$\begingroup\$

It is common to start countdowns 100 days prior to an event, probably because of our base 10 system. Examples of this can be found everywhere:

  • 100 days until your birthday
  • 100 days until the wedding
  • 100 days until the election
  • 100 days until our graduation
  • 100 days until her due date
  • 100 days until football season
  • 100 days until you get the Fanatic badge

You get the picture. It seems that the 100th day before an event is second place only to the actual event. So for this challenge, I need to know what the date will be in 100 days, so that I can determine what I should start counting down too.

Input

No input

Output

The date 100 days from the current date based on the standard Gregorian Calendar (Make sure to account for leap years). Output is flexible as long as the date format is human read-able (eg 2016-10-8, 10-8-16, [ 2016, 10, 8 ], 10/8/16 12:00:00 AM).

Winning

Code golf: shortest code in bytes


Examples

100 days from today (Apr 5th, 2017) is Friday, July 14 2017.

Current                Future
-------                ------
01/01/2001 +100        04/11/2001
01/01/2004 +100        04/10/2004
01/01/1900 +100        04/11/1900
01/01/2000 +100        04/10/2000

07/04/2017 +100        10/12/2017
10/31/2017 +100        02/08/2018
12/25/2017 +100        04/04/2018

08/29/1941 +100        12/07/1941
06/03/2001 +100        09/11/2001
\$\endgroup\$
10
  • 2
    \$\begingroup\$ Can I add the current time to the output? \$\endgroup\$
    – Titus
    Commented Apr 6, 2017 at 4:05
  • 2
    \$\begingroup\$ @Titus no, just the future date \$\endgroup\$ Commented Apr 6, 2017 at 10:30
  • 1
    \$\begingroup\$ Most answers include a date and time now, I think this should be allowed. \$\endgroup\$
    – G B
    Commented Apr 6, 2017 at 12:25
  • 5
    \$\begingroup\$ "Because of our bas 10 system"? No, if we counted in binary, we'd likely count down from 100 - except that would take only four days, rather than a hundred... \$\endgroup\$ Commented Apr 6, 2017 at 12:54
  • 2
    \$\begingroup\$ @12431234123412341234123 this format is perfectly readable for me (in fact, it's pretty much a de-facto standard where I live). It all depends on where you're from. \$\endgroup\$ Commented Apr 8, 2017 at 20:30

45 Answers 45

42
\$\begingroup\$

Excel, 10

=NOW()+100

Demonstration

enter image description here

\$\endgroup\$
9
  • 1
    \$\begingroup\$ Also works in Google Sheets. \$\endgroup\$
    – Okx
    Commented Apr 6, 2017 at 11:00
  • 11
    \$\begingroup\$ Excel is always good for code golf that involves parsing dates. \$\endgroup\$ Commented Apr 6, 2017 at 12:21
  • 2
    \$\begingroup\$ Is there a language pack for excel in which the NOW function is spelled out with just two letters? In that case, you could save 1 byte. \$\endgroup\$
    – iFreilicht
    Commented Apr 7, 2017 at 9:20
  • 14
    \$\begingroup\$ Yep, Dutch has 'nu()' \$\endgroup\$
    – Tominator
    Commented Apr 7, 2017 at 9:31
  • 2
    \$\begingroup\$ Although, per date part only, you'd have to use =TODAY()+100 or =TEXT(NOW()+100,"MM/dd/yyyy") \$\endgroup\$
    – KyleMit
    Commented Apr 7, 2017 at 19:36
20
\$\begingroup\$

Bash, 17 16 15 14 13 bytes

date -d100day

It turns out the date command takes some pretty flexible input for relative timings. You can also do things like 1 year, 1 week ago, yesterday, etc. It's pretty cool.

-1 byte by realizing that bash does not care about grammar.
-1 byte because the space between 100 and day is unnecessary.
-1 byte because I don't need quotes anymore because I don't have a space in the string.
-1 byte by removing the space after -d (thanks ASCII-only!)

\$\endgroup\$
4
  • \$\begingroup\$ New favorite command +1 \$\endgroup\$ Commented Apr 6, 2017 at 2:32
  • \$\begingroup\$ @NonlinearFruit Hah, yeah, it's probably one of my favorite commands. Thanks! \$\endgroup\$
    – hyperneutrino
    Commented Apr 6, 2017 at 2:37
  • \$\begingroup\$ You don't need the space after -d \$\endgroup\$
    – ASCII-only
    Commented Apr 6, 2017 at 2:47
  • \$\begingroup\$ @ASCII-only Oh, okay. Thanks! \$\endgroup\$
    – hyperneutrino
    Commented Apr 6, 2017 at 2:47
10
\$\begingroup\$

PowerShell, 10 bytes

(date)+1e2

Thanks to ConnorLSW for the +1e2 trick.

It appears that doubles (1e2 is a double) are also added as days.

Previous version, 12 bytes:

(date)+"100"

Apparently you can add strings to dates in PowerShell. The string "100" is converted into a 100 days-TimeSpan.

\$\endgroup\$
6
  • 2
    \$\begingroup\$ Ok don't ask me why, but even though (date)+100 doesn't work, (date)+1e2 does... I guess 1e2 is actually a double whereas 100 is a number until it's compiled, i.e. you can't call 100.GetType() but you can 1e2.GetType() - that's -2 and brings us to a draw with Excel! \$\endgroup\$
    – colsw
    Commented Apr 6, 2017 at 16:18
  • \$\begingroup\$ @ConnorLSW If it help or adds to the confusion 100 is seen as adding 100 ticks where as the string "100" is taken as days. Both are valid PS but only one does what we need. \$\endgroup\$
    – Matt
    Commented Apr 6, 2017 at 18:32
  • \$\begingroup\$ @Matt 1e6 is still a number and is added as days though? \$\endgroup\$
    – colsw
    Commented Apr 6, 2017 at 18:33
  • \$\begingroup\$ That is interesting then. Perhaps there is more going on under the hood where that number reaches over a threshold.... I do not know \$\endgroup\$
    – Matt
    Commented Apr 6, 2017 at 18:35
  • \$\begingroup\$ I think it's somehow related to the old DATE type which is an 8-byte floating point number with days being represented as whole number increments. I guess that's what Excel is using. \$\endgroup\$ Commented Apr 6, 2017 at 19:15
8
\$\begingroup\$

Mediawiki, 19bytes

{{#time:r|+100day}}

You may try it with wikipedia's sandbox

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ Commented Apr 8, 2017 at 11:05
6
\$\begingroup\$

PHP, 28 bytes

<?=date(Y_m_d,time()+864e4);

human readable version, 35 bytes:

<?=date(Y_m_d,strtotime("100day"));

almost readable, 34 bytes:

<?=date(Y_m_d,strtotime(1e2.day));

-4 bytes if also printing the time is accepted: replace Y_m_d with r or c.

It´s National Holiday in France in 100 days.

\$\endgroup\$
2
  • \$\begingroup\$ The underscores made me do "Why underscores, is it a constant? No, a string OH WAIT 'SPACES'!!" Clever. \$\endgroup\$
    – Martijn
    Commented Apr 7, 2017 at 7:58
  • \$\begingroup\$ @Martijn Turn on E_NOTICE and You´ll know: Y_m_d is an undefined constant and PHP assumes a string. This works with any valid word (including all function names) apart from keywords, predefined constants and case insensitive true, false and null. \$\endgroup\$
    – Titus
    Commented Apr 7, 2017 at 10:42
5
\$\begingroup\$

Ruby, 16 bytes

p Time.now+864e4

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Was going to answer this, nice. But I get different results for 864e4 and 8640000 and I don't quite know why. I blame TIO. EDIT: when you use p, the two values produce a different result. But when you use puts, they're the same. \$\endgroup\$
    – snail_
    Commented Apr 10, 2017 at 13:09
  • \$\begingroup\$ I don't understand, I get the same result with both. Can you post an example? Maybe it depends on the locale? \$\endgroup\$
    – G B
    Commented Apr 10, 2017 at 13:41
  • \$\begingroup\$ p Time.now+864e4 is around 4 days behind p Time.now+8640000 on TIO. I tried it multiple times. However, if you use puts, this distinction doesn't exist. I don't really know if my locale matters, US East should be pretty normal :P I guess I'll try running it on my own PC when I get home. \$\endgroup\$
    – snail_
    Commented Apr 10, 2017 at 15:15
5
\$\begingroup\$

Javascript, 29 26 25 bytes

Saved 3 bytes thanks to @ASCII-only!

Saved 1 byte thanks to @JohanKarlsson

new Date(+new Date+864e7)

document.body.innerHTML=new Date(+new Date+864e7)

\$\endgroup\$
3
  • 1
    \$\begingroup\$ You can use 864e7 instead of 864*10e6 \$\endgroup\$
    – ASCII-only
    Commented Apr 6, 2017 at 10:18
  • 1
    \$\begingroup\$ You can save 1 byte by using +new Date instead of Date.now() \$\endgroup\$ Commented Apr 6, 2017 at 12:00
  • 1
    \$\begingroup\$ This is a snippet. You need to include console.log \$\endgroup\$
    – mbomb007
    Commented Apr 7, 2017 at 16:10
5
\$\begingroup\$

SQL (PostgreSQL), 19 Bytes

SELECT now()+'100d'
\$\endgroup\$
4
\$\begingroup\$

Vim, 27 bytes

:r!date "+\%F" -d"+100 day"

try it online!

enter image description here

Edit: Removed unnecessary space char.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ If you're using Linux date, the one on this page is date -d100day, not sure if it will help though \$\endgroup\$
    – ASCII-only
    Commented Apr 6, 2017 at 10:26
  • \$\begingroup\$ I test it with :r!date +\%F -d100day this also works (at least on my pc (C)), but is the same as HyperNeutrino already use in bash. \$\endgroup\$ Commented Apr 7, 2017 at 11:03
  • \$\begingroup\$ Uh, you can save bytes by just eliminating vim and doing it in bash. \$\endgroup\$ Commented Apr 8, 2017 at 8:05
4
\$\begingroup\$

MATL, 9 bytes

Z'100+1XO

Output format is 15-Jul-2017 (which I find most readable). Change 1XO to 2XO to get the format used in the examples, 07/15/17.

Try it online!

Explanation

Z'      % Push current date and time as a serial date number
100+    % Add 100
1XO     % Convert to string with format 'dd-mmm-yyyy'. Implicitly display
\$\endgroup\$
4
\$\begingroup\$

SQL (Microsoft), 35 31 bytes

SELECT DATEADD(D,100,GETDATE())
\$\endgroup\$
2
  • \$\begingroup\$ You can use d instead of DAY and remove the spaces inside DATEADD. \$\endgroup\$
    – mbomb007
    Commented Apr 6, 2017 at 16:27
  • \$\begingroup\$ Even I didn't know you could use d. I use dd or day in practice. I just tried it and it worked. \$\endgroup\$
    – mbomb007
    Commented Apr 7, 2017 at 3:12
3
\$\begingroup\$

Java 8, 77, 61 bytes

()->System.out.print(java.time.LocalDate.now().plusDays(100))

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Is there a reason you don't include the boilerplate? (ie 'class A{public static. . .') For Java, I believe at is necessary for a full program. You could do a lambda ()->java.time.LocalDate.now().plusDays(100). \$\endgroup\$ Commented Apr 6, 2017 at 10:34
  • \$\begingroup\$ I had that before editing my answer. It was 94 bytes along with the boilerplate. I new to golfing with java. hence I aint sure about whether I had to include that! \$\endgroup\$ Commented Apr 6, 2017 at 10:46
  • 2
    \$\begingroup\$ Submissions (unless otherwise specified) can be either a full program (runnable by some interpreter without modification) or a function. \$\endgroup\$ Commented Apr 6, 2017 at 12:22
3
\$\begingroup\$

C#, 103 97 bytes

Thanks to raznagul for saving 6 bytes!

using System;class P{static void Main(){Console.Write(DateTime.Now.AddDays(100).ToString("d"));}}

Full program which reads the current date, adds 100 days and displays the result in M/d/YYYY format.

You can change the date format by adding a few more bytes:

using System;class P{static void Main(){Console.Write(DateTime.Now.AddDays(100).ToString("d-M-yyyy"));}}

To eliminate boilerplate code - C# isn't exactly known to be very compact - an anonymous function can be used:

C# lambda, 49 43 bytes

()=>DateTime.Now.AddDays(100).ToString("d")

Full program:

using System;

class P
{
    static void Main()
    {
        Func<string> f = 
        ()=>DateTime.Now.AddDays(100).ToString("d");
        
        Console.WriteLine(f());
    }
}
\$\endgroup\$
3
  • \$\begingroup\$ For the full program I think you can write System.DateTime.Now... to avoid "using System;" \$\endgroup\$
    – Taemyr
    Commented Apr 6, 2017 at 7:33
  • 1
    \$\begingroup\$ @Taemyr: That would be longer, as he also needs it for Console.Write. \$\endgroup\$
    – raznagul
    Commented Apr 6, 2017 at 8:17
  • 2
    \$\begingroup\$ @adrianmp: You can save save 6 bytes by using .ToString("d") instead of .ToShortDateString(). \$\endgroup\$
    – raznagul
    Commented Apr 6, 2017 at 8:24
3
\$\begingroup\$

Noodel, 8 bytes

]5@LaƇ⁺ƈ

Try it:)


How it works

]5@LaƇ⁺ƈ
]5@La    # The string "]5@La" gets pushed onto the stack which in base 98 represents 8,640,000,000.
     Ƈ   # Pushes an integer that represents the current time where highest resolution is milliseconds.
      ⁺  # Add the time and the string which will be interpreted as 8,640,000,000ms.
       ƈ # Convert the integer to human readable time.
         # Implicitly output to the screen.

<div id="noodel" code="]5@LaƇ⁺ƈ" input="" cols="80" rows="2"/>

<script src="https://tkellehe.github.io/noodel/noodel-latest.js"></script>
<script src="https://tkellehe.github.io/noodel/ppcg.min.js"></script>

\$\endgroup\$
2
  • \$\begingroup\$ The character Ƈ is the unicode character U+0187, which is too large to be displayed in a single byte. Same goes for ƈ (U+0188). So while this is 8 characters long, the minimum byte-length is 10. \$\endgroup\$
    – iFreilicht
    Commented Apr 7, 2017 at 9:33
  • 1
    \$\begingroup\$ @iFreilicht, Noodel uses its own encoding. The editor does everything in UTF-16 to work better visually, but gets encoded based off of the Noodel code page before parsing. \$\endgroup\$
    – tkellehe
    Commented Apr 7, 2017 at 10:24
3
\$\begingroup\$

Mathematica, 26 21 bytes

-5 bytes thanks to @KiranLinsuain!

Today+Quantity@"100d"

If including the time is permitted, then we can save 2 bytes:

Now+Quantity@"100d"
\$\endgroup\$
1
  • 1
    \$\begingroup\$ "Now + Quantity["100d"]" cuts it down quite a bit, but may not always work on all versions. \$\endgroup\$
    – lmnopcdefg
    Commented Apr 7, 2017 at 5:41
3
\$\begingroup\$

C, 87 46 44 bytes

saved 2 bytes thanks to Albert Renshaw

f(){time_t t=time(0)+864e4;puts(ctime(&t));}

I realized the output is flexible enough to allow for day of week and time, so there's no need to use localtime or the tm structure at all.

Old answer

f(){time_t t=time(0)+8640000;char b[9];strftime(b,9,"%d-%m-%y",localtime(&t));puts(b);}

Based on Khaled.K's answer, but instead of messing with the tm structure, adds the number of seconds equivalent to 100 days directly to the time_t value. It also prints only the date, without time or day of week.

As it should happen on a golfed program, some ugly warnings are generated on compilation.

Try it online!

Ungolfed:

f(){
    // Current time + 100 days
    time_t t=time(0)+8640000;
    // Buffer for printing formatted time
    char b[9];
    // Print the time in format dd-mm-yy to buffer
    strftime(b,9,"%d-%m-%y",localtime(&t));
    // print buffer
    puts(b);
}
\$\endgroup\$
1
  • 2
    \$\begingroup\$ Shave 2 bytes by replacing 8640000 with 864e4 \$\endgroup\$ Commented Apr 7, 2017 at 7:43
2
\$\begingroup\$

JavaScript, 42 bytes

(d=new Date()).setDate(d.getDate()+100)&&d

setInterval(_=>document.body.innerHTML=(d=new Date()).setDate(d.getDate()+100)&&d,1000)

\$\endgroup\$
1
2
\$\begingroup\$

IBM/Lotus Notes Formula, 29 bytes

@Adjust(@Today;0;0;100;0;0;0)

Unfortunately @Adjust requires the trailing 0's for the missing hh:mm:ss.

If we were allowed to display the time as well then changing @Today to @Now would save 2 bytes for 27.

\$\endgroup\$
2
\$\begingroup\$

JavaScript (ES6), 44 bytes

_=>new Date(Date.now()+864e7).toDateString()

25 bytes if returning a date with the time is acceptable:

_=>Date(Date.now()+864e7)
\$\endgroup\$
2
\$\begingroup\$

30 bytes

Mysql!

select NOW()+INTERVAL 100 DAY;

SQLite

SELECT date('now','+100 day');
\$\endgroup\$
2
\$\begingroup\$

F# (53 bytes)

printf"%s"(DateTime.Now.AddDays(100.0).ToString("d"))
\$\endgroup\$
1
  • \$\begingroup\$ Don't see a lot of F# answers on here. Kudos! \$\endgroup\$ Commented Apr 8, 2017 at 8:16
2
\$\begingroup\$

Swift 3, 39 bytes

print(Date(timeIntervalSinceNow:864E4))
\$\endgroup\$
3
  • \$\begingroup\$ I'd argue you don't need the import foundation;. Swift runs just on iOS and that is auto imported there. \$\endgroup\$ Commented Apr 7, 2017 at 7:37
  • \$\begingroup\$ There aren't too many Swift answers here yet, so not sure what the consensus is. But I think you have a good point, I'll remove the import :) \$\endgroup\$
    – Matt
    Commented Apr 7, 2017 at 10:11
  • \$\begingroup\$ @Albert Swift also runs on Mac OS and Linux. I don't know what that means for whether the import is required, though. \$\endgroup\$ Commented Apr 8, 2017 at 8:10
2
\$\begingroup\$

C, 120 113 bytes

#include <time.h>
f(){time_t t=time(0);struct tm*tm=localtime(&t);tm->tm_mday+=100;t=mktime(tm);printf("%s",ctime(&t));}

Live Demo

#include <stdio.h>
#include <time.h>

void PrintDatePlus100days()
{
    // obtain current time
    time_t t = time( 0 );

    // convert to datetime struct
    struct tm *tm = localtime( &t );

    // add 100 days
    tm->tm_mday += 100;

    // convert to time_t
    t = mktime( tm );

    // print time in readable format
    puts( ctime( &t ) );
}
\$\endgroup\$
3
  • \$\begingroup\$ If I'm not mistaken, you don't need to account for #include ... boilerplate when submitting functions. (Java answers, for example, don't need import in that case) \$\endgroup\$ Commented Apr 6, 2017 at 23:43
  • \$\begingroup\$ @CássioRenan in Java you don't need to count the default imports like java.lang.*, just like how we don't count stdio.h and stdlib.h in C. But even in java, you need to either consider custom imports or put the path in the class name like java.util.Date, and that counts in your score. \$\endgroup\$
    – Khaled.K
    Commented Apr 7, 2017 at 9:03
  • 2
    \$\begingroup\$ Why using printf() would puts() not also work? \$\endgroup\$ Commented Apr 7, 2017 at 11:04
2
\$\begingroup\$

PowerShell, 23

(get-date).adddays(100)

This is my first ever try, so please give me constructive feedback. Thanks!

\$\endgroup\$
2
\$\begingroup\$

R (REPL), 14 bytes

Sys.Date()+100

Try it on Ideone.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ This is a snippet. Your code is required to output the result, either as the result of a function, or to STDOUT as a full program. \$\endgroup\$
    – mbomb007
    Commented Apr 6, 2017 at 20:25
  • \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$
    – mbomb007
    Commented Apr 7, 2017 at 16:04
  • \$\begingroup\$ @mbomb007 REPL answers are allowed, but they're considered a separate language. \$\endgroup\$
    – Dennis
    Commented Apr 11, 2017 at 22:35
  • \$\begingroup\$ @Dennis It wasn't listed as REPL before. \$\endgroup\$
    – mbomb007
    Commented Apr 12, 2017 at 3:48
1
\$\begingroup\$

Python, 63 bytes

from datetime import*
print(datetime.now()+timedelta(days=100))

Very simple solution really. Because the datetime.now() result is the same type as the result of timedelta, it happily adds the two together.

\$\endgroup\$
9
  • \$\begingroup\$ It doesn't have to be a function. You could remove the lambda: and it would still be a full program. \$\endgroup\$ Commented Apr 6, 2017 at 3:15
  • \$\begingroup\$ @NonlinearFruit Yes but print would have to be added and that makes it the same number of bytes. \$\endgroup\$
    – user67196
    Commented Apr 6, 2017 at 3:20
  • \$\begingroup\$ If you use Python 2, you can remove brackets in print to save 1 byte \$\endgroup\$ Commented Apr 6, 2017 at 9:26
  • \$\begingroup\$ the days= is optional, that would save 5+1 bytes (python2 print's brackets) \$\endgroup\$ Commented Apr 6, 2017 at 11:10
  • \$\begingroup\$ Golfed down to 57 bytes: from datetime import*;print datetime.now()+timedelta(100) \$\endgroup\$
    – Mr. Xcoder
    Commented Apr 6, 2017 at 13:16
1
\$\begingroup\$

JavaScript, 38 Bytes

d=new Date;d.setDate(d.getDate()+100);d

A little bit shorter than ASCII-only answer.

document.write(eval("d=new Date;d.setDate(d.getDate()+100);d"))

\$\endgroup\$
1
\$\begingroup\$

Golang, 58 bytes

import ."time"
func f(){Println(Now().AddDate(0, 0, 100))}

Full Program

package main

import . "time"
import . "fmt"

func main() {
    Println(Now().AddDate(0, 0, 100))
}

try it online!

\$\endgroup\$
1
\$\begingroup\$

Oracle, 34 bytes

SELECT CURRENT_DATE+100 FROM DUAL;
\$\endgroup\$
1
\$\begingroup\$

Python 2 + Pandas 0.19.1, 56 51 bytes

from pandas import*
print Timestamp('now','D')+100
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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