[Question]
  [
## Challenge
Weirdly, this hasn't been done yet: output the current date.
## Rules
The date format you should follow is as follows:
```
YYYY-MM-DD
```
Where the month and day should be padded by zeroes if they are less than 10.
For example, if the program is run on the 24th May 2017, it should output
```
2017-05-24
```
The date can either be always in UTC or in the local date.
You must handle leaps years. i.e. in leap years, February has 29 days but 28 days in a normal year.
## Winning
Shortest code in bytes wins.
  
[Answer]
# [Bash](https://tio.run/nexus/bash#@5@SWJKqoK3q9v8/AA) with [GNU coreutils](https://www.gnu.org/software/coreutils/), ~~16~~ 7 bytes
-8 bytes thanks to Neil (and fergusq) (no pipe required to output)  
-1 byte thanks to 12431234123412341234123 (use the built-in option with flag `-I`!)
```
date -I
```
**[Try it online!](https://tio.run/nexus/bash#@5@SWJKqoOv5//9/AA)**
[Answer]
# PHP, 17 bytes
```
<?=date('Y-m-d');
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 6 bytes
```
Ks3 ¯A
```
[Try it online!](https://tio.run/nexus/japt#@@9dbKxwaL3j//8A "Japt – TIO Nexus")
## Explanation:
```
Ks3 ¯A
K       // New Date()
 s3     // .toISOString()
    ¯A  // .slice(0,10)
```
[Answer]
# Bash, 15 bytes
```
printf '%(%F)T'
```
Sample run:
```
bash-4.4$ printf '%(%F)T'
2017-05-24
```
[Try it online!](https://tio.run/nexus/bash#@19QlJlXkqagrqqh6qYZov7/PwA "Bash – TIO Nexus")
[Answer]
## JavaScript (ES6), 34 bytes
```
_=>new Date().toJSON().split`T`[0]
```
```
f=
_=>new Date().toJSON().split`T`[0]
console.log(f());
```
[Answer]
# SQLite, 13 characters
```
select date()
```
Good boy, SQLite. Other SQL dialects usually need either `current_date` or `date(now())`.
Sample run:
```
bash-4.4$ sqlite3 <<< 'select date()'
2017-05-24
```
[Answer]
## Mathematica, 20 bytes
```
DateString@"ISODate"
```
[Answer]
# [Perl 6](https://perl6.org), ~~14~~ 12 bytes
```
Date.today.say
```
[Try it](https://tio.run/nexus/perl6#Ky1OVSgz00u2/u@SWJKqV5KfklipV5xY@f//17x83eTE5IxUAA "Perl 6 – TIO Nexus")
```
now.Date.say
```
[Try it](https://tio.run/nexus/perl6#Ky1OVSgz00u2/p@XX67nkliSqlecWPn//9e8fN3kxOSMVAA "Perl 6 – TIO Nexus")
[Answer]
# Excel, 24 bytes
```
=TEXT(NOW(),"yyy-mm-dd")
```
Excel will still do a 4-digit year with only 3 `y`'s.
[Answer]
# [R](https://www.r-project.org/), 10 bytes
```
Sys.Date()
```
[Try it online!](https://tio.run/nexus/r#@x9cWaznkliSqqH5/z8A "R – TIO Nexus")
[Answer]
# jq, 19 characters
(15 characters code + 4 characters command line options)
```
now|todate[:10]
```
Sample run:
```
bash-4.4$ jq -nr 'now|todate[:10]'
2017-05-24
```
[Try in jq‣play](https://jqplay.org/s/TtdTTXsPIO)
[Answer]
# Lua, 18 characters
```
print(os.date"%F")
```
Sample run:
```
bash-4.4$ lua -e 'print(os.date"%F")'
2017-05-24
```
[Try it online!](https://tio.run/nexus/lua#@19QlJlXopFfrJeSWJKqpOqmpPn/PwA "Lua – TIO Nexus")
[Answer]
## [Alice](https://github.com/m-ender/alice), 9 bytes
```
/oT\
@%;'
```
[Try it online!](https://tio.run/nexus/alice#@6@fHxLD5aBqrf7/PwA "Alice – TIO Nexus")
### Explanation
I'll leave the exact control flow as an exercise to the reader, but the linearised code that is being run in Ordinal mode is:
```
%T'T%;o@
```
And here is what it does:
```
%   Split an implicit empty string around an implicit empty string. Really doesn't
    do anything at all.
T   Push the current datetime as a string like "2017-05-24T20:53:08.150+00:00"
'T  Push "T".
%   Split the datetime string around the "T", to separate the date from the time.
;   Discard the time.
o   Output the date.
@   Terminate the program.
```
One way this might be golfable is to reuse the `%` to terminate the program in Cardinal mode with a division by zero, but the only layout I've come up with is the following:
```
\;T
\%o'
```
But here, the `%` doesn't actually terminate the program, because we push 111 (`'o`) right beforehand so there's never a division by zero.
In principle it might also be possible to reuse `%` to get rid of the `;`, since trying to split the date around the time will simply discard the time.
[Answer]
# SmileBASIC 3, 29 bytes
SB has a date string built in... but it's in the wrong format! It uses slashes instead of dashes, no good. Plus, being the self-respecting BASIC it is, there is no global replace function. I guess I have to do it myself...
```
D$=DATE$D$[4]="-
D$[7]="-
?D$
```
[Answer]
# Java 8, ~~26~~ 32 bytes
```
()->java.time.LocalDate.now()+""
```
Fixed format thanks to Kevin Cruijssen
[Answer]
# VBA, 5 25 bytes
`?Date` *unpredictable, dependent on system short date settings*
```
?Format(Now,"yyyy-mm-dd")
```
### Output:
```
2017-05-25 
```
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 46 bytes
```
f(X):-get_time(Y),format_time(atom(X),'%F',Y).
```
[Try it online!](https://tio.run/##KyjKz8lP1y0uz/z/P00jQtNKNz21JL4kMzdVI1JTRyEtvyg3EcpPLMnPBarQUVBXdVPXUYjU1INo0QMA "Prolog (SWI) – Try It Online")
[Answer]
# Pyth, 19 bytes
`++++.d3"-".d4"-".d5`
In Pyth `.` allows you to access a number of extra syntactic goodies. `d` contains various date options which are accessed with `.d#`, where `#` is a number 0-9. `3` is for the current year, `4` is the current month, and `5` is for the current day.
Format for the challenge wants dashes between each element of the date so we append them. Pyth using Polish notation for all math operands, thus the `++++`.
[Answer]
# [Factor](https://factorcode.org/), 21 bytes
```
[ now timestamp>ymd ]
```
[Try it online!](https://tio.run/##S0tMLskv@h8a7OnnbqWQnVqUl5qjkJyYk5qXklgEZ@il5RflJpYoZOYrWP@PVsjLL1coycxNLS5JzC2wq8xNUYj9D1Sao1BQlJlX8h8A "Factor – Try It Online")
[Answer]
# x86-16 machine code, IBM PC DOS, ~~55~~ ~~53~~ 48 bytes
Binary:
```
00000000: b42a cd21 91b3 64f6 f38b c8e8 1400 8ac5  .*.!..d.........
00000010: e80f 00b0 2dcd 298a c6e8 0600 b02d cd29  ....-.)......-.)
00000020: 8ac2 d40a 0530 3050 86c4 cd29 58cd 29c3  .....00P...)X.).
```
Listing:
```
B4 2A       MOV  AH, 2AH        ; get system date: CX=year, DH=month, DL=day 
CD 21       INT  21H            ; call DOS API
91          XCHG AX, CX         ; move year in CX to AX (dividend)
B3 64       MOV  BL, 100        ; divide by 100 to separate digits of year
F6 F3       DIV  BL             ; AL = first two digits, AH = last two digits
8B C8       MOV  CX, AX         ; save AX to CX to display last two digits later 
E8 0122     CALL DISP_WORD      ; display decimal value in AL 
8A C5       MOV  AL, CH         ; move last two digits to AL 
E8 0122     CALL DISP_WORD      ; display decimal value in AL 
B0 2D       MOV  AL, '-'        ; date separator 
CD 29       INT  29H            ; fast write AL to screen
8A C6       MOV  AL, DH         ; move month in DH into AL for display 
E8 0122     CALL DISP_WORD      ; display decimal value in AL 
B0 2D       MOV  AL, '-'        ; date separator 
CD 29       INT  29H            ; fast write AL to screen 
8A C2       MOV  AL, DL         ; move day into AL and display 
        DISP_WORD: 
D4 0A       AAM                 ; convert binary to BCD 
05 3030     ADD  AX, '00'       ; convert BCD to ASCII char 
50          PUSH AX             ; save second digit for display later 
86 C4       XCHG AL, AH         ; convert endian, AL = first digit, AH = second digit 
CD 29       INT  29H            ; fast write AL to screen
58          POP  AX             ; restore digits
CD 29       INT  29H            ; fast write AL to screen 
C3          RET                 ; return to caller/DOS
```
***Output***
Standalone DOS program, run from the command line outputs current date to the screen.
[![enter image description here](https://i.stack.imgur.com/Csg39.png)](https://i.stack.imgur.com/Csg39.png)
Much of this program is converting binary values to ASCII for console output. This uses (abuses) the binary-to-BCD instruction (`AAM`) to create a printable ASCII version of the output.
[Answer]
# TI-Basic, 72 bytes
```
getDate→A
toString(Ans(1→B
toString(ʟA(2→C
toString(ʟA(3→D
If C<10
"0"+C→C
If D<10
"0"+D→D
B+"-"+C+"-"+D
```
This only works on a TI-84+ CE OS 5.2 and if the user has already set the time and date correctly.
[Answer]
## [QBIC](https://drive.google.com/drive/folders/0B0R1Jgqp8Gg4cVJCZkRkdEthZDQ), 33 bytes
```
B=_D?_sB,-4|+@-`+_sB,2|+A+_sB,4,2
```
Explanation:
```
B=_D        Assign the system's date to B$
            This is in American mm-dd-yyyy format, so we'll need to do some reformatting
?_sB,-4|    PRINT substring B, take 4 chars from the right
 +@-`         plus the string literal "-", now A$
 +_sB,2|      plus the leftmost two chars
 +A           and A$ again
 +_sB,4,2     plus the middle part.
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), ~~22~~ 15 bytes
```
et3<{sY0e[}%'-*
```
[Try it online!](https://tio.run/nexus/cjam#@59aYmxTXRxpkBpdq6quq/X/PwA "CJam – TIO Nexus")
-7 bytes thanks to Challenger5.
Explanation:
```
et                       Get array with [year,month,day,stuff...]
  3<                     Slice array to get [y,m,d] 
    {                    For each item do:
     s                     To string
      Y0e[                 add a 0 to the beginning of the string if it is shorter than 2 chars.
          }%             End for each
            '-*          Join the array with "-" as a separator
```
[Answer]
# Python 2, 40 bytes
```
from datetime import*;print date.today()
```
[Answer]
# [Go](https://golang.org/), ~~62~~ 56 bytes
```
import."time"
func f()string{return Now().String()[:10]}
```
[Try it online!](https://tio.run/nexus/go#K0hMzk5MT1XITczM48rMLcgvKtFTSsstUfoP45Rk5qYqcaWV5iUrpGloFpcUZealVxellpQW5Sn45ZdraOoFg8U0NKOtDA1ia/@DlYLM09Cs5lIAggCgdIkGULMmV@1/AA "Go – TIO Nexus")
[Answer]
# Oracle SQL, 46 bytes
```
SELECT TO_CHAR(SYSDATE,'YYYY-MM-DD') FROM DUAL
```
[Answer]
# Powershell, ~~26~~ 17 bytes
```
Date -f yyy-MM-dd
```
Thanks to @ConnorLSW for the 9 bytes.
[Answer]
# Ruby, 23 bytes
Prints the local time.
```
p Time.now.strftime'%F'
```
[Answer]
# MATLAB/[Octave](https://www.gnu.org/software/octave/), ~~25~~ 15 bytes
```
datestr(now,29)
```
[Try it online!](https://tio.run/nexus/octave#@5@SWJJaXFKkkZdfrmNkqfn/PwA "Octave – TIO Nexus")
---
The built-in function `now` returns the current system date in a weirdy MATLAB serial format.
`datestr` formats the weirdy serial format into a string of a requested format - which is in this case `'YYYY-mm-dd'`. It turns out that MATLAB has a list of predefined formats for `datestr`. ISO8601 is one of them and is represented by the number 29, which allows a saving of 10 bytes.
[Answer]
# [Python 2](https://docs.python.org/2/), ~~53~~ 40 bytes
-10 bytes thanks to Gábor Fekete (ISO-8601 is the default format for a date object)
```
from datetime import*
print date.today()
```
**[Try it online!](https://tio.run/nexus/python2#@59WlJ@rkJJYklqSmZuqkJlbkF9UosVVUJSZVwIW1ivJT0ms1ND8/x8A)**
### How?
`datetime.date.today()` will return a `datetime.date` object containing the local date information.
`print` will print a string representation of that object, this will call the object's `__str__` function.
From the [docs](https://docs.python.org/2/library/datetime.html):
* `date.__str__()`: For a `date` `d`, `str(d)` is equivalent to `d.isoformat()`.
* `date.isoformat()`: Return a `string` representing the date in **ISO 8601** format, `‘YYYY-MM-DD’`. For example, `date(2002, 12, 4).isoformat() == '2002-12-04'`.
]