# Tag Info

## New answers tagged date

1

Raku (raku -n file-with-one-line) 118 Bytes /(..)(.)(.)(..)/;$!=10*$1+$2;die if 12 <$!||1>$!;$!=7.5-abs(7.5-$!);$!=($!+|4)+^1 if$!!= 2;Date.new($3%4??0!!1,$!,$0) Result as exit code (0: ok, 1: error) 2 Swift 279 277 272 264 262 257 256 254 252 bytes func v(s:String)->Int{let m=Int(s.suffix(4).prefix(2))!;switch m{case 0,13...:return 0;case _:switch Int(s.prefix(2))!{case 1...28:return 1;case 29,30:return Int(s.suffix(4))!%4==0&&m==2 ?0:1;case 31:return[4,6,9,11].contains(m) ?1:0;case _:return 0}}} My first and most probably failed attempt at ... 2 Bash + GNU utilities, 86 85 83 82 bytes a=0424343443434;fold -2|xargs|(read d m y;date -d${a:${m#0}:1}/$d/0$[!(${y#0}%4)]) Try it online! Input is on stdin. Output is the exit code: 0 for truthy, 1 for falsey. I thought I'd do a solution based on a date built-in, since I don't think anyone else has done that yet. This program takes the input string $x\... 2 Java (JDK), 74 bytes n->{int m=n/100%100;return(m==2?n%4<1?2:1:~m%9%2)<31-(n/=1e4)&13>m&n*m>0;} Try it online! Credits -1 byte thanks to ceilingcat -3 bytes thanks to Kevin Cruijssen 3 05AB1E, 34 bytes 2ô¨Ðθ©13‹sĀPr2QiI4Ö≠ë®7(%ÉÌ}29+‹P Just an initial answer. Can definitely be golfed by a few bytes. Inspired by both @Arnauld's JavaScript answer and @SurculoseSputum's Python answer, so make sure to upvote them!! Try it online or verify all test cases. Explanation: 2ô # Split the (implicit) input in parts of size 2: ddmmyy →... 1 ArnoldC, 676 bytes IT'S SHOWTIME HEY CHRISTMAS TREE n YOU SET US UP 0 GET YOUR ASS TO MARS n DO IT NOW I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY HEY CHRISTMAS TREE s YOU SET US UP 0 GET TO THE CHOPPER s HERE IS MY INVITATION n I LET HIM GO 100 ENOUGH TALK HEY CHRISTMAS TREE m YOU SET US UP 0 GET TO THE CHOPPER m ... 4 Jelly, 28 bytes Ɠ⁽¿ÇB31_+2¦4ḍ~ƊR;€"Jḅ³Fċ:³ A full program accepting a single integer from STDIN which prints a 1 or 0 to STDOUT. Try it online! Or see the test-suite. How? Ɠ⁽¿ÇB31_+2¦4ḍ~ƊR;€"Jḅ³Fċ:³ - Main Link Ɠ - set the chain's left argument, N, to evaluated STDIN ⁽¿Ç - base 250 integer = 3765 ... 5 Retina 0.8.2, 96 93 91 81 bytes ^(?!(..)?00|..[2-9]|..1[3-9]|31(?!0[469]|11)|3002|2902([02468][048]|[13579][26])) Try it online! Link includes test cases. Edit: Saved 3 bytes thanks to @mathjunkie. Saved 2 bytes thanks to @ThomasAyoub. Saved a further 10 bytes thanks to @ThomasAyoub for noting that the day cannot be greater than 31. Explanation: ^ Match ... 7 Python 3.8, 77 67 65 62 61 bytes -2 bytes thanks to @Bubbler -3 bytes thanks to @xnor -1 byte thanks to @PoonLevi's mod by float trick lambda s:13>(m:=s//100%100)>0<s//1e4<30-[s%4<1,m%-1.76][m!=2] Try it online! Input: Date as an integer. Output: True or False if the date is valid or invalid respectively. How: Overall approach: return ... 2 C (gcc), 95$\cdots$71 65 bytes Saved 3 4 bytes thanks to ceilingcat!!! Saved a whopping 15 bytes thanks to Olivier Grégoire!!! Saved 6 bytes thanks to Arnauld!!! Takes the date as an integer and returns$0$or$1$. m;f(s){m=s/100%100;s=m<13&(m-2?~m%9%2-1:s%4<1)+(s/=1e4)<30&&s*m;} Try it online! 2 Perl 5 Mbigint -p, 76 75 bytes /(..)(..)/;_=1>0&&1<substr 113130-(_%4?0:1).31323132313132313231,2*2,2 Try it online! 2 Python 3.8, 136$\cdots$93 78 bytes Takes the date as an integer and returns Truthy or Falsy. lambda s,h=100:13>(m:=s//h%h)>0<s//h//h<(30-(s%4<1),31+(m in(4,6,9,11)))[m!=2] Try it online! 15 JavaScript (ES6), 62 60 59 bytes Takes input as a 0-padded string. Returns$0$for false or a positive integer for true. s=>(m=s[2]+s[3])<13&31-(m^2?~m%9%2:s%4?1:2)>(s/=1e4)&&~~s*m Try it online! or Check all possible outputs against an ungolfed implementation Commented s => // s = input string (m =... 1 Ruby -apl, 102 bytes Takes input as a line of input from STDIN with space as the separator. Outputs false if the dates are ambiguous and the days of week don't match. In order to make sure we get a correct date the first time, we sort the first two arguments to ensure the smaller of the two (which is guaranteed to be less than 13) is placed in the month ... 1 Excel, 85 Bytes =IF(OR(DAY(A1)>12,MOD(A1-DATE(YEAR(A1),DAY(A1),MONTH(A1)),7)=0),TEXT(A1,"ddd"),"???") Input the date into cell A1 Since Excel will automatically evaluate the date into a valid form for us, we can first check if the Day is >12, since this would immediately make the date unambiguous. We then work out if difference between the "dd/mm/yyyy"... 3 Ruby, 48 44 bytes -4 bytes thanks to Value Ink! Differs from other answers so far in that it (i) takes no input and (ii) has a unique$t_1$for every day of the year. p (t=*Time.now)[2]%12+t[1]<1||t[1,2]==t[3,2] Try it online! (actual code) Try it online! (demo version showing the three times that will return true on a given date) Outputs true at ... 1 W, 5 bytes ... With True and False swapped around; they're distinctive anyway. ♥─y¥• Uncompressed: !26bm> Explanation ! % Check whether the input is equal to 0 b % Push the second input 26 m % Push 26 % b > % Is input == 0 larger than the above value? 0 Io, 19 bytes Port of @Arnauld's answer... method(U,V,26%U>=V) Try it online! 1 perl -ple, 18 bytes _=/(2[01]|08):00/ Reads a time in HH:MM format from STDIN (optionally preceded by a date in YYYY-MM-DD format (or anything else which doesn't like a time)). Print 1 followed by a newline if the time is 08:00, 20:00 or 21:00; otherwise, it prints a single newline. 1 Jelly, 7 6 bytes Turns out porting Arnauld's answer is a byte shorter than my original answer (which I've kept below) 26%<¬} A dyadic Link accepting the hour (an integer in [0,23]) on the left and the minute (an integer in [0,59]) on the right which yields 1 at three times (not varying by day), 2,0 (02:00), 1,0 (01:00), and 13,0 (13:00). ... 1 Perl 5 -MTime::Local=timegm_modern -pF'/', 116 113 108 bytes sub f{_[1]--;eval{timegm_modern 0,0,9,@_}}_=(a=f@g=@F)*(b=f@F[1,0,2])&a-b?Err:substr gmtime(a|b),0,3 Try it online! Tries converting both formats into an epoch time. The eval traps the error that would occur for an invalid date. Multiplies the two epoch times together to make sure ... 1 Ruby, 19 bytes Returns true at 6:00, 12:00, 18:00. ->h,m{h>0&&m|h%6<1} Try it online! 1 Retina, 18 17 bytes + Bonus imaginary Internet points (.)T(11|23|0\1)00 Try it online! Note that TIO is having technical issues at the moment, so the link that it gave me above may or may not work. Thanks to @mypronounismonicareinstate for pointing out that the ISO 8601 allows omitting the colon in the time part, which saves a byte in the code. (ISO ... 11 Bash + Core utilities, 26 25 bytes + Bonus imaginary Internet points! egrep '(.)T(11|23|0\1)00' Try it online! Thanks to @mypronounismonicareinstate for pointing out that the ISO 8601 allows omitting the colon in the time part, which saves a byte in the code. (ISO 8601 also allows omitting the hyphens in the date, but that doesn't affect the regex.) This ... 2 Python 3, 21 bytes lambda h,m:26%-~h<m<2 Try it online! Input: hour and minute, as integers Output: True if the time is 00:01,01:01,12:01, otherwise False. 3 C (gcc), 22$\cdots$20 19 bytes Saved a byte thanks to Arnauld!!! f(h,m){h=26%~h<!m;} Try it online! Returns 1 for noon, midnight and 1am, 0 otherwise. Adaptation of Arnauld's formula. 2 Python 3, 35$\cdots$22 19 bytes Saved a byte thanks to Arnauld!!! Saved 3 bytes thanks to Surculose Sputum!!! lambda h,m:26%~h==m Try it online! Returns True for noon, midnight and 1am, False otherwise. Adaptation of Arnauld's formula. 2 05AB1E (legacy), 5 bytes _₂I%› Port of @Arnauld's JavaScript answer, so make sure to upvote him!! Takes two loose inputs, in the order minutes, hours. Will also output 1 for any of these three times below, and 0 on any other time:$t_{am}$= 01:00$t_{pm}$= 13:00$t_1$= 02:00 Try it online or verify some more test cases. Explanation: _ # ... 3 Japt -!, 8 bytes Inspired by Kevin's choice of times. Input as 2 integers in the order h, m. Outputs true at 00:00, 01:01 and 13:01 and false otherwise. %C*VÉ©Nx Try it %C*VÉ©Nx :Implicit input of integers U=h and V=m %C :U modulo 12 (=1 if U=1 or U=13) *V :Multiplied by V (=1 if above and V=1) É :Subtract 1 (=0 if all ... 18 JavaScript (ES6), 13 bytes Takes input as (h)(m). Returns true for 01:00, 02:00 and 13:00, or false for anything else. h=>m=>26%h<!m Try it online! How? Testing$26\bmod h<\delta_m$is equivalent to test that we have$m=0$and$26\equiv 0\pmod h$. For$0<h\le23$, we have$26\equiv 0\pmod h$iff$h$divides$26$, i.e.$h\in\...

1

Charcoal, 10 bytes ⁼²№⟦↨Ｓ⁴Ｎ⟧⁹ Try it online! Link is to verbose version of code. Takes input as hour and minute separated by a space, on separate lines, or as a JSON list i.e. [22, 10], and outputs - for 09 09, 15 09 and 21 09 only. Explanation: ⟦ ⟧ List of Ｓ Hours as a string ↨ ⁴ Interpreted as base 4 Ｎ Minutes № ...

1

Perl 5 -lF: , 34 bytes say$F[0]%12&&$F[0]!=1||$F[1]>0?0:1 Try it online! Reads current time input from stdin in hh:mm format. Outputs 1 at 00:00, 01:00, and 12:00; 0 at all other times. 4 R, 23 bytes function(h,m)26%%h|m|!h Try it online! Port of Arnauld's solution, go upvote his! Outputs FALSE at 1:00, 13:00 and 2:00, and TRUE otherwise. Previous version: R, 26 bytes function(h,m)!h|m|(h/6)%%1 Try it online! Outputs FALSE at the three times: $t_{am}$ = 6:00 $t_{pm}$ = 18:00 $t_1$ = 12:00 and TRUE at any other time. Indeed, ... 1 Retina 0.8.2, 28 bytes ^.$&$&$&$& \G\d$* ^1{8}:18 Try it online! Link includes test cases. Explanation: ^. $&$&$&$& Repeat the hour tens digit four times. \G\d $* Convert the hour digits to unary. ^1{8}:18 They must sum to 8 and the minutes must be 18 (arbitrarily chosen to reuse the same digits). 1 Python 3.8 (pre-release), 125 bytes Improvement over @Noodle9's answer lambda a,b,y:[.1,w:=g(y,a,b)][w==g(y,b,a)] g=lambda y,m,d:m<13and date(y,m,d).strftime("%a")or g(y,d,m) from datetime import* Try it online! Input: 3 integers representing date, month, and year. Output: A 3-character abbreviation of a weekday, or 0.1 if the weekday is ambiguous. ... 2 05AB1E, 16 11 10 bytes Taking input in the format [minutes, hours]: 12%*ΘIO_~ Try it online. Without input and using the current time builtins: ža12%žb*Θžažb+_~ Try it online (not very useful right now..) or try it online with emulated hours/minutes. Both programs use the three times: $t_{am}$ = 1:01 $t_{pm}$ = 13:01 $t_1$ = 00:00 And will ... 2 PHP, 115 bytes foreach(['/','-']as$s){if($x=strtotime(strtr($argn,'/',$s)))$o=date('D',$x);if($p&&$o!=$p)die('err');$p=$o;}echo$p; Try it online! Uses the peculiarity that the builtin strtotime parses dates as either European or American format according to whether the delimiter is either slash or dash. Takes input as a/b/Y and returns err for an ... 2 Python, 180 164 158 bytes Saved 3 bytes thanks to Kevin Cruijssen and Arnauld!!! Saved 3 bytes thanks to Surculose Sputum!!! lambda a,b,c:(x:=d(a,b,c))==(y:=d(b,a,c))and x or(x and y and.1)or y or x from datetime import* def d(a,b,y): try:return date(y,a,b).strftime("%a") except:0 Try it online! Assumes we can input the date as three separate ... 3 JavaScript (ES6), 136 132 131 bytes Returns "Err" for an error. s=>'SunMonTueWedThuFriSatErr'.match(/.../g)[[i,j]=([d,m,y]=s.split/).map(M=>new Date(y,M-1,M^m^d).getDay()),d<13?m>12|i==j?i:7:j] Try it online! Commented s => // s = input string 'SunMonTueWedThuFriSatErr' // lookup string .match(... 8 05AB1E, 88 82 79 76 79 73 72 bytes #ÂÀ‚Dε`UÐ3‹12*+>₂*T÷s3‹Xα¬Ésт%D4÷O.•A±₁γβCüIÊä6’C•3ôsè}DËiнës€¨13‹WiтëθÏ -3 bytes thanks to @Arnauld (initially -6, but +3 bytes again, since Jan./Feb. 2000 would still result in the previous century in the formula). -7 bytes thanks to @Grimmy. Input is space-separated; and outputs in lowercase with 100 as error. Try ... 3 Red, 186 169 167 bytes -2 bytes thanks to Kevin Cruijssen func[d][a: to-date t: load form split d"/"m: min a b: to-date reduce[t/2 t/1 t/3]either any[a/10 = b/10 t/1 > 12 t/2 > 12][pick[:Mon:Tue:Wed:Thu:Fri:Sat:Sun]m/10][.1]] Try it online! Takes the input as string, because Red doesn't accept invalid dates in dd/mm/yyyy format. That's strange, ... 2 Perl 5 -MPOSIX -naF/, 125 bytes sub d{substr ctime(mktime 6,0,0,$_[0],$_[1]-1,$_[2]-1900),0,3}@G=@F[1,0,2];say$F[0]>12?d@F:$F[1]>12?d@G:d(@F)eq d(@G)?d@F:Err Try it online! Not completely happy with this one, but haven't thought up a better way (yet).

6

Bash + GNU utilities, 97 96 93 85 80 76 73 58 56 51 bytes (${d=date +%a -d$3-}$1-$2;$d$2-$1)|uniq|sed N\;cErr Try it online! 5 bytes off thanks to user41805, who pointed out that I could use sed's c command instead of the final s command. 2 bytes off thanks to Nahuel Fouilleul. (Nahuel also helped by shaving 4 bytes off in an earlier version that has ... 4 Perl 6, 124 121 bytes {<Err Mon Tue Wed Thu Fri Sat Sun>[2>set($/=|grep ?*,map {try Date.new(|$_).day-of-week},m:g/\d+/[[2,1,0],[2,0,1]])&&$0]} Try it online!

Top 50 recent answers are included