Give me the first day of next month

Simple question!

Given a string that contains a date in ISO8601 format, print the first of the next month in ISO8601 format.

Example inputs:

2018-05-06

2019-12-20

Their respective outputs:

2018-06-01

2020-01-01

The rules:

• Imports are free and don't count towards your score.
• The date will be stored in a string called s.
• The solution with the least characters, wins
• Please avoid creating new tags unless they're really missing. We already have date and parsing. The beginner tag is an interesting idea, but I think that should be discussed in meta. On the other hand, you must include a tag telling what's the winning criterion. Is this code-golf? – Arnauld Dec 13 '19 at 10:27
• I suggest removing The date will be stored in a string called s. and leave it up to the answerers to use any of the default I/O methods. Btw, reading from a pre-defined variable is not among those defaults. Also, not all languages have strings, and not all languages have variables. – Adám Dec 13 '19 at 10:31
• Do you mean the output should be stored in s, or that the input would be stored in s? – Kobe Dec 13 '19 at 11:00
• @Arnauld There was discussion around that topic (a "beginner" or "easy" tag) quite a while ago with no clear consensus. IMO that's still the case because it's very subjective. – AdmBorkBork Dec 13 '19 at 14:40
• I'd say, the newly-added The solution with the least characters, wins could count as the winning criteria, but we prefer not to specify a variable that the input/output have to be stored inside – Shieru Asakoto Dec 20 '19 at 1:19

JavaScript (V8), 67, 57, 56 bytes

-10 thanks to Arnauld,
-1 joining template string and ternary

s=>([a,b]=s.split-,+a+!(b%=12))+-${b++<9?'0'+b:b}-01  Test cases: f=s=>([a,b]=s.split-,+a+!(b%=12))+-${b++<9?'0'+b:b}-01

console.log(f('2018-12-20'))
console.log(f('2019-05-06'))

• 57 bytes (without assuming that the input is stored in s, as this unusual requirement will hopefully be removed) – Arnauld Dec 13 '19 at 11:12
• I never knew you could do that with split, thanks for the input. Might I also ask what's happening with the -~b part? @Arnauld – Kobe Dec 13 '19 at 11:25
• -~b is -(-b-1) and works on non-numeric values. But since b is already coerced to a number by the modulo, you can actually just use b+1 here. – Arnauld Dec 13 '19 at 11:28
• @Kobe -~b is basically b+1 (or actually -(-b-1)). It can be useful to skip parenthesis sometimes, although it's not really necessary in this case, so you could change it to b+1 being more readable if you'd prefer. Relevant tip. You might also find Tips for golfing in JavaScript and Tips for golfing in <all languages> interesting to read through. Welcome to CGCC! – Kevin Cruijssen Dec 13 '19 at 11:29
• @KevinCruijssen Thanks for the comment and links, I'll definitely take a look at those soon :) – Kobe Dec 13 '19 at 11:31

Bash, 31, 24 bytes

7 bytes saved thanks to @manatwork and @nwellnhof

date -d${1%??}1month +%F  Try it online! • Wow! date's parsing ability keeps amazing me. BTW, I think you can skip the “0”. – manatwork Dec 13 '19 at 10:57 Ruby 49 bytes d=Date.parse(s);print Date.new(d.year,d.mon,1)>>1  Online repl PHP, 57 bytes [$y,$m]=explode('-',$s);$m=++$m%13?:!!++$y;$d="$y-$m-1";


Test cases:

<?php
function next_month($s) { [$y,$m]=explode('-',$s);
$m=++$m%13?:!!++$y; return "$y-$m-1"; }$s = "2018-05-06";
echo next_month($s); // Gives 2018-6-1$s = "2019-12-20";
echo next_month($s); // Gives 2020-1-1  • Consider using Try it online! to demonstrate your code. – Neil Dec 21 '19 at 20:42 Red, 39 bytes t: load s t/month: t/month + t/day: 1 t  Retina 0.8.2, 33 bytes T9dd.9*(-12)?-..$
-23|-..$-01  Try it online! Link includes test cases. Explanation: T9dd  Increment with wrap-around... .9*(-12)?-..$


... the last non-9 digit, plus trailing 9s, in either the year or the month, depending on whether the month is 12. (Digits in the following date parts also get incremented.)

-23|-..\$
-01


Replace the day with 01. Also, if the month was 12 before, it will be 23 now, and also needs to be reset to 01.