g | x | w | all
Bytes Lang Time Link
017Pip210630T001132ZDLosc
012TIBasic221118T024347ZYouserna
030Mathematica210702T183758ZLance
020K ngn/k210702T103509Zmkst
035Perl 5210701T152715ZKjetil S
024Excel210630T124348ZCrissov
032JavaScript Node.js210630T000149Zmrmonkin
051Python 3210630T110121ZSevC_10
041Python 3210630T132453ZHunaphu
018Excel formula210630T143714ZSpencer
042PHP210630T074349ZKaddath
057R210630T121240ZDominic
nan210629T181528ZJeff Zei
027C gcc210629T215018ZNoodle9
040R210630T073808Zpajonk
059Desmos210629T212816ZAiden Ch
017Vyxal210629T204700Zemanresu
033JavaScript210630T023531Ztsh
027Haskell210629T192459Zlynn
029Factor210629T215854Zchunes
006Gaia210629T215019Zovs
016Japt210629T213359ZShaggy
015Jelly210629T175158Zcaird co
014Vyxal s210629T204606Za stone
009MATL210629T180531ZLuis Men
016Bash210629T180017ZDigital
036Perl 5 p210629T193538ZNahuel F
036JavaScript ES6210629T182740ZArnauld
020Charcoal210629T185038ZNeil
036Red210629T183558ZGalen Iv
011APL Dyalog Unicode210629T175326ZAdá
141Java210629T174259Zkaiffeet

Pip, 24 23 17 bytes

275*a//9-30+b-2%a

Uses the formula from lynn's Haskell solution. Attempt This Online!


Original approach, 23 bytes:

b+$+A*""@<Da

The code contains unprintable characters. Here's a hexdump:

00000000: 622b 242b 412a 221f 1c1f 1e1f 1e1f 1f1e  b+$+A*".........
00000010: 1f1e 2240 3c44 61                        .."@<Da

Attempt This Online!

Explanation

                         a (month) and b (day) are command-line arguments
      "..........."      String containing characters with codes 31, 28, 31, etc.
                         for the months January through November
    A*                   Get the ASCII code of each character
                     Da  Decrement a
                   @<    The first (^ that many) items of the list of charcodes
  $+                     Sum
b+                       Add b

TI-Basic, 12 bytes

dbd(101.1,Ans+.1

Takes input in Ans as an integer in the format DDMM (for example, November 23 is 2311).

Mathematica, 30 bytes

{1}~DateDifference~{1,#,#2+1}&

Try it here!

Returns as a quantity object: Example screenshot

Using the DateDifference builtin and the fact that {y} is treated as January 1st on year y. I thought of {1}~DateDifference~{##}& at first, but sadly DateDifference starts from 0 days instead of 1.

K (ngn/k), 25 20 bytes

Solution:

{+/y,x#28+4\3390446}

Try it online!

Explanation:

Assumes months are 0-indexed!

Naive approach, there are likely better ones out there.

{+/y,x#28+4\3390446} / the solution
{                  } / lambda taking implicit x, y args
          4\3390446  / creates 3 0 3 2 3 2 3 3 2 3 2 from base-4           
       28+           / add 28 to each item (vectorised)
     x#              / take 'month' items from this list (January = 0)
   y,                / prepend 'days'
 +/                  / sum up

Edits:

Extra:

Perl 5, 35 bytes

Just a translation of the Haskell answer from @Lynn

$_=int 275*$F[0]/9-30+$F[1]-2%$F[0]

Try it online!

Excel, 30 24 bytes

Edit: I used the year 2001 before, because I do not trust Excel with dates before 1905.

JavaScript (Node.js), 35 32 bytes

m=>d=>--m*31+d-'003344555667'[m]

Try it online!

Thanks to A username for pro golf tips!

Python 3, 60 55 51 bytes, 1-based month

lambda function that accepts the month (1-based) and the day.

-5 bytes: used a "31-days" default month, and the list s accounts for the cumulate (absolute) difference between the actual days of months and 31
-4 bytes: the list is removed from the function parameters, thanks to @Hunaphu and @mic_e

lambda m,d,a=[3,0,3,2,3,2,3,3,2,3,2]:28*(m-1)+sum(a[:m-1])+d  # original version

lambda m,d,s=[0,0,3,3,4,4,5,5,5,6,6,7]:31*m-31-s[m-1]+d

lambda m,d:31*m-31-[0,0,3,3,4,4,5,5,5,6,6,7][m-1]+d

Try it online!

Explanation (original version):


Python 3, 56 50 46 bytes, 0-based month

-4 bytes (compared to 1-based month number): if 0-based month number is allowed as input
-6 bytes: used the "31-days" approach
-4 bytes: the list is removed from the function parameters, thanks to @Hunaphu and @mic_e

lambda m,d,a=[3,0,3,2,3,2,3,3,2,3,2]:28*(m)+sum(a[:m])+d  # original version

lambda m,d,s=[0,0,3,3,4,4,5,5,5,6,6,7]:31*m-s[m]+d

lambda m,d:31*m-[0,0,3,3,4,4,5,5,5,6,6,7][m]+d

Python 3, 41 bytes

lambda m,d:31*~-m-(539785049600>>3*m&7)+d

Try it online!

Python 3, 41 chars, 50 bytes

lambda m,d:d+ord('0\x00>v´ðĮŪƨǦȢɠʜ'[m])/2

Try it online!

Excel formula, 18 Bytes

=DATE(1,A1,B1)-366

Saved 8 bytes from answer by Crissov by evaluating the offset as 366, then added 2 bytes by converting named ranges m and d into cell references.

If leap years were allowed, then it could be shortened to a single function =DATE(0,A1,B1)

PHP, 42 bytes

fn($m,$d)=>date(z,mktime(0,0,0,$m,$d,1))+1

Try it online!

Pretty much builtin. The year parameter could be omitted, but the current year would then be used. To avoid a leap year 1 was used (it actually corresponds to 2001 according to the doc). 1 is added because the result is zero indexed.

This is satisfying, the byte count is The Answer, which is also the answer to the test case!

1 byte shorter but less satisfying:

PHP, 41 bytes

fn($m,$d)=>date(z,strtotime("1-$m-$d"))+1

Try it online!

R, 57 bytes

(my own attempt)

function(m,d){F[c(8:14,2:8)]=30:31;F[3]=28;sum(F[1:m],d)}

Try it online!

An alternative R solution to pajonk's answer, without using any date built-ins.


R, 34 bytes

(port of Lynn's answer)

function(m,d)(275*m)%/%9-30+d-2%%m

Try it online!

This works on my PowerShell 5 on my computer; I can't get it working on TIO:

PowerShell 5, 97 bytes

function s($m,$d){1+(New-Timespan -st (Get-Date -day 1 -mo 1) -e (Get-Date -day $d -mo $m)).Days}

Call as s 2 11 for the example date (month before day-of-month).

Golfed by @mazzy, 82 bytes

PowerShell, 82 bytes

param($m,$d)1+(New-Timespan -st (Date -day 1 -mo 1) -e (Date -day $d -mo $m)).Days

Try it online!

The golfing relies on an alias or implementation of command (Date) that does not exist in a default Windows 10 installation of PowerShell 5. The TIO PowerShell is PowerShell 6 on Linux.

C (gcc), 47 27 bytes

f(d,m){m=275*m/9-30+d-2%m;}

Try it online!

Uses formula from Lynn's Haskell answer.

R, 40 bytes

function(m,d)format(ISOdate(1,m,d),"%j")

Try it online!

Using buildins, returning as string.


Returning as a number (also using buildins):

R, 44 bytes

function(m,d)as.POSIXlt(ISOdate(1,m,d))$yd+1

Try it online!

Desmos, 90 82 59 bytes

f(m,d)=total([0,31,28,31,30,31,30,31,31,30,31,30][1...m])+d

Saved 23 bytes 'cause I was so dumb... I've been trying to do some clever list manipulation to save bytes, but it never came to my mind to just put the list itself.

Very Brief Explanation:

[0,31,28,31,30,31,30,31,31,30,31,30]: The number of days in each month(excluding December), with an extra 0 element at the beginning.

total( ... [1...m])+d: Sum of the first m elements of the list explained above, then add d.

Try It On Desmos!

Try It On Desmos! - Prettified

Solution using Lynn's "closed form" formula, 34 bytes

f(m,d)=floor(275m/9)-30+d-mod(2,m)

Vyxal, 17 bytes

»∇ė{»4τ28+¦0p?‹i+

Try it Online! Works now, and -2.

JavaScript, 33 bytes

m=>d=>((m+9)%12*51+99)*.6%365+d|0

Try it online!

Haskell, 27 bytes

m%d=div(275*m)9-30+d-mod 2m

Try it online!

This is a “closed-form” answer (in a C-like language it would be 275*m/9-30+d-2%m).

Factor, 29 bytes

[ 1 -rot <date> day-of-year ]

Try it online!

Gaia, 6 bytes

A dyadic function taking the month above the day. Gaia has a nice collection of date/time builtins.

(∂k<Σ+

Try it online!

(       # decrement the month
 ∂k     # push list [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] (builtin)
   <    # take the first month-1 elements from this list
    Σ   # sum them
     +  # add the day

Japt, 16 bytes

Well, this ain't right :\ Normally Japt would be ruling the roost in a date based challenge but not this time, despite all the tricks I can muster. Which makes me seriously worried that, after 16 long months, I've lost my edge when it comes to golfing on me phone over a few pints down the boozer!

ÒÐBì)nÐUi¹z864e5

Try it

Jelly, 16 15 bytes

“LɓịNH’D+28⁸;ḣS

Try it online!

Takes \$d\$ then \$m\$ on the command line

“LɓịNH’D+28⁸;ḣS - Main link. Takes d on the left and m on the right
“LɓịNH’         - Compressed integer; 303232332323
       D        - Convert to digits; [3, 0, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3]
        +28     - Plus 28 to each; [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
           ⁸;   - Prepend d; [d, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
             ḣ  - Take the first m
              S - Sum

Vyxal s, 14 bytes

‹»HȦð9E»fẎ28+p

Try it Online! Port of @caird's Jelly solution

‹»HȦð9E»fẎ28+p    
 »HȦð9E»          Push compressed integer 303232332323
        f         Convert to digits 
‹        Ẏ        Slice [0:m-1]
          28+     Add 28 to each list element
             p    Prepend to the day of the month

s flag: Sums the top of the stack and outputs the sum.

MATL, 9 bytes

14Liq:)hs

Try it online!

Explanation

14L % Push [31 28 31 30 31 30 31 31 30 31 30 31]: month lengths (predefined literal)
i   % Input: month, m
q   % Subtract 1
:   % Inclusive range from 1 to that
)   % Index into the array of month lengths: gives its first m-1 terms
h   % Implicit input: day, d. Concatenate with previous array
s   % Sum of array. Implicit display

Bash, 16

date -d$1/1 +%-j

Input is given on the command-line as slash-separated integers, with month first.

Try it online!

Perl 5 (-p), 36 bytes

/ /;$_=strftime"%-j",(0)x3,$',$`-1,0

Try it online!

JavaScript (ES6),  40 37  36 bytes

Expects (day)(month).

d=>g=m=>--m?31-(4/m&2)+~m%9%2+g(m):d

Try it online!

How?

This is a recursive function that computes the number of days in each full month (i.e. lower than \$m\$), sums them all together and finally adds \$d\$ on the last iteration.

We use 4 / m & 2 to distinguish between February and all other months:

We use ~m % 9 % 2 to subtract \$1\$ for months that do not have \$31\$ days:

    m |   1 |   2 |   3 |   4 |   5 |   6 |   7 |   8 |   9 |  10 |  11
   ~m |  -2 |  -3 |  -4 |  -5 |  -6 |  -7 |  -8 |  -9 | -10 | -11 | -12
mod 9 |  -2 |  -3 |  -4 |  -5 |  -6 |  -7 |  -8 |   0 |  -1 |  -2 |  -3
mod 2 |   0 |  -1 |   0 |  -1 |   0 |  -1 |   0 |   0 |  -1 |   0 |  -1

(This also works for December, but we never have to compute the total number of days in this month.)

Charcoal, 20 bytes

I⁺↨E…”)“M⟧₂”⊖N⁻³¹ι¹N

Try it online! Link is to verbose version of code. Explanation:

     ”)“M⟧₂”            Compressed string `03010100101`
    …                    Truncated to length
             N          Month as an integer
            ⊖           Decremented
   E                     Map over characters
                ³¹       Literal integer `31`
               ⁻         Subtract
                  ι      Current value
  ↨                ¹     Take the sum
 ⁺                       Plus
                    N    Day as an integer
I                        Cast to string
                         Implicitly print

Base 1 conversion is used in case the list is empty (i.e. January).

Red, 36 bytes

func[m d][pick to now reduce[d m]11]

Try it online!

APL (Dyalog Unicode), 11 bytes

Full program. Prompts for [month,day]

1⎕DT⊂1900,⎕

Try it on TryAPL! ( is stdin, but is emulated with the variable since TryAPL doesn't allow stdin)

 prompt for [month,day]; [2,11]

1900, prepend 1900; [1900,2,11]

 enclose to represent as scalar time stamp; [[1900,2,11]]

1⎕DT convert DateTime to days since 1899-12-31; 42

Java, 141 bytes

int d(int d,int m){for(int i=1;i<m;i++){switch(i){case(2):d+=28;break;case(4):case(6):case(9):case(11):d+=30;break;default:d+=31;}}return d;}