Palindrome dates: Difference between revisions

Added Easylang
m (Replaced "UNIX shell" by "UNIX Shell" (to link the example to the existing category page))
(Added Easylang)
 
(37 intermediate revisions by 24 users not shown)
Line 6:
Write a program which calculates and shows the next 15 palindromic dates for those countries which express their dates in the   '''yyyy-mm-dd'''   format.
<br><br>
 
=={{header|11l}}==
{{trans|Java}}
 
<syntaxhighlight lang="11l">V date = Time(2020, 2, 3)
print(‘First 15 palindrome dates after 2020-02-02 are:’)
V count = 0
L count < 15
V date_formatted = date.format(‘YYYYMMDD’)
I date_formatted == reversed(date_formatted)
print(‘date = ’date.format(‘YYYY-MM-DD’))
count++
date += TimeDelta(days' 1)</syntaxhighlight>
 
{{out}}
<pre>
First 15 palindrome dates after 2020-02-02 are:
date = 2021-12-02
date = 2030-03-02
date = 2040-04-02
date = 2050-05-02
date = 2060-06-02
date = 2070-07-02
date = 2080-08-02
date = 2090-09-02
date = 2101-10-12
date = 2110-01-12
date = 2111-11-12
date = 2120-02-12
date = 2121-12-12
date = 2130-03-12
date = 2140-04-12
</pre>
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">TYPE Date=[
INT year
BYTE month
BYTE day]
 
BYTE FUNC IsLeapYear(INT y)
IF y MOD 100=0 THEN
IF y MOD 400=0 THEN
RETURN (1)
ELSE
RETURN (0)
FI
FI
IF y MOD 4=0 THEN
RETURN (1)
FI
RETURN (0)
 
BYTE FUNC GetMaxDay(INT y BYTE m)
BYTE ARRAY MaxDay=[31 28 31 30 31 30 31 31 30 31 30 31]
 
IF m=2 AND IsLeapYear(y)=1 THEN
RETURN (29)
FI
RETURN (MaxDay(m-1))
 
PROC NextDay(Date POINTER d)
BYTE maxD
 
d.day==+1
maxD=GetMaxDay(d.year,d.month)
IF d.day>maxD THEN
d.day=1
d.month==+1
IF d.month>12 THEN
d.month=1
d.year==+1
FI
FI
RETURN
 
BYTE FUNC IsPalindrome(Date POINTER d)
INT y
 
y=d.year
IF y/1000#d.day MOD 10 THEN
RETURN (0)
FI
y==MOD 1000
IF y/100#d.day/10 THEN
RETURN (0)
FI
y==MOD 100
IF y/10#d.month MOD 10 THEN
RETURN (0)
FI
y==MOD 10
IF y#d.month/10 THEN
RETURN (0)
FI
RETURN (1)
 
PROC PrintB2(BYTE x)
IF x<10 THEN
Put('0)
FI
PrintB(x)
RETURN
 
PROC PrintDateShort(Date POINTER d)
PrintI(d.year) Put('-)
PrintB2(d.month) Put('-)
PrintB2(d.day)
RETURN
 
PROC Main()
BYTE count
Date d
 
count=0
d.year=2020 d.month=2 d.day=3
WHILE count<15
DO
IF IsPalindrome(d) THEN
PrintDateShort(d) PutE()
count==+1
FI
NextDay(d)
OD
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Palindrome_dates.png Screenshot from Atari 8-bit computer]
<pre>
2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12
</pre>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Uses the Algol 68G local time routine which is non-standard.
<syntaxhighlight lang="algol68">BEGIN # print future palindromic dates #
# a palindromic date must be of the form demn-nm-ed #
# returns a string representation of n with at least 2 digits #
PROC two digits = ( INT n )STRING:
BEGIN
STRING result := whole( ABS n, 0 );
IF ( UPB result - LWB result ) + 1 < 2 THEN "0" +=: result FI;
IF n < 0 THEN "-" +=: result FI;
result
END # two digits # ;
# possible years for a palindromic date #
[]INT mn = ( 1, 10, 11, 20, 21, 30, 40, 50, 60, 70, 80, 90 );
# months corresponding to the year for for a palindromic date #
[]INT nm = ( 10, 1, 11, 2, 12, 3, 4, 5, 6, 7, 8, 9 );
# possible centuaries for a palindromic date #
[]INT de = ( 10, 11, 12, 13, 20, 21, 22, 30, 31, 32, 40, 41, 42, 50
, 51, 52, 60, 61, 62, 70, 71, 72, 80, 81, 82, 90, 91, 92
);
# days corresponding to the centuary for a palindromic date #
[]INT ed = ( 1, 11, 21, 31, 2, 12, 22, 3, 13, 23, 4, 14, 24, 5
, 15, 25, 6, 16, 26, 7, 17, 27, 8, 18, 28, 9, 19, 29
);
# max days per month ( february handled specifically in code ) #
[]INT max dd = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
# current date in local time (Algol 68G extension) #
[]INT date = local time;
INT yy now = local time[ 1 ] MOD 100;
INT cc now = local time[ 1 ] OVER 100;
INT dates to print := 15; # maximum number of dates to print #
FOR c pos FROM LWB de TO UPB de WHILE dates to print > 0 DO
INT cc = de[ c pos ];
INT dd = ed[ c pos ];
FOR y pos FROM LWB nm TO UPB nm WHILE dates to print > 0 DO
INT mm = nm[ y pos ];
INT yy = mn[ y pos ];
IF cc > cc now OR ( cc = cc now AND yy > yy now ) THEN
# have a possible future date #
IF dd <= max dd[ mm ]
OR ( mm = 2 AND dd = 29 AND yy MOD 4 = 0 )
THEN
# have a valid future date #
# no need to test yy = 0 as dd = 0 is impossible #
dates to print -:= 1;
print( ( two digits( cc )
, two digits( yy )
, "-"
, two digits( mm )
, "-"
, two digits( dd )
, newline
)
)
FI
FI
OD
OD
END</syntaxhighlight>
{{out}}
<pre>
2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12
</pre>
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO;
with Ada.Calendar.Formatting;
with Ada.Calendar.Arithmetic;
Line 41 ⟶ 265:
Date := Date + 1;
end loop;
end Palindrome_Dates;</langsyntaxhighlight>
 
=={{header|AppleScript}}==
===Procedural===
<langsyntaxhighlight lang="applescript">on palindromeDates(startYear, targetNumber)
script o
property output : {}
Line 76 ⟶ 300:
end palindromeDates
 
palindromeDates(2021, 15)</langsyntaxhighlight>
 
{{output}}
Line 83 ⟶ 307:
===Functional===
 
<langsyntaxhighlight lang="applescript">use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
Line 199 ⟶ 423:
set my text item delimiters to dlm
str
end unlines</langsyntaxhighlight>
{{Out}}
<pre>Count of palindromic dates [2021..9999]: 284
Line 236 ⟶ 460:
9280-08-29
9290-09-29</pre>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">date := 20200202
counter := 0
 
while (counter < 15) {
date += 1, days
date := SubStr(date, 1, 8)
if (date = reverse(date))
{
FormatTime, fdate, % date, yyyy-MM-dd
output .= fdate "`n"
counter++
}
}
 
MsgBox, 262144, , % output
return
 
reverse(n){
for i, v in StrSplit(n)
output := v output
return output
}</syntaxhighlight>
{{out}}
<pre>
2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12
</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f PALINDROME_DATES.AWK
BEGIN {
Line 271 ⟶ 537:
return(rts)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 291 ⟶ 557:
21211212 92800829
21300312 92900929
</pre>
 
 
=={{header|BASIC}}==
 
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">
dateTest = ""
mes = 0 : dia = 0 : anno = 0 : Pal = 0
total = 0
print "Siguientes 15 fechas palindrómicas al 2020-02-02:"
for anno = 2021 to 9999
dateTest = ltrim(string(anno))
for mes = 1 to 12
if mes < 10 then dateTest = dateTest + "0"
dateTest = dateTest + ltrim(string(mes))
for dia = 1 to 31
if mes = 2 and dia > 28 then exit for
if (mes = 4 or mes = 6 or mes = 9 or mes = 11) and dia > 30 then exit for
if dia < 10 then dateTest = dateTest + "0"
dateTest = dateTest + ltrim(string(dia))
for Pal = 1 to 4
if mid(dateTest, Pal, 1) <> mid(dateTest, 9 - Pal, 1) then exit for
next Pal
if Pal = 5 then
total += 1
if total <= 15 then print left(dateTest,4);"-";mid(dateTest,5,2);"-";right(dateTest,2)
end if
if total > 15 then exit for : exit for : exit for
dateTest = left(dateTest, 6)
next dia
dateTest = left(dateTest, 4)
next mes
dateTest = ""
next anno
end
</syntaxhighlight>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
{{trans|FreeBASIC}}
<syntaxhighlight lang="basic">
dateTest$ = ""
total = 0
 
PRINT "Siguientes 15 fechas palindr¢micas al 2020-02-02:"
FOR anno = 2021 TO 9999
dateTest$ = LTRIM$(STR$(anno))
FOR mes = 1 TO 12
IF mes < 10 THEN dateTest$ = dateTest$ + "0"
dateTest$ = dateTest$ + LTRIM$(STR$(mes))
FOR dia = 1 TO 31
IF mes = 2 AND dia > 28 THEN EXIT FOR
IF (mes = 4 OR mes = 6 OR mes = 9 OR mes = 11) AND dia > 30 THEN EXIT FOR
IF dia < 10 THEN dateTest$ = dateTest$ + "0"
dateTest$ = dateTest$ + LTRIM$(STR$(dia))
FOR Pal = 1 TO 4
IF MID$(dateTest$, Pal, 1) <> MID$(dateTest$, 9 - Pal, 1) THEN EXIT FOR
NEXT Pal
IF Pal = 5 THEN
total = total + 1
IF total <= 15 THEN PRINT LEFT$(dateTest$, 4); "-"; MID$(dateTest$, 5, 2); "-"; RIGHT$(dateTest$, 2)
END IF
IF total > 15 THEN
EXIT FOR: EXIT FOR: EXIT FOR
END IF
dateTest$ = LEFT$(dateTest$, 6)
NEXT dia
dateTest$ = LEFT$(dateTest$, 4)
NEXT mes
dateTest$ = ""
NEXT anno
END
</syntaxhighlight>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> INSTALL @lib$ + "DATELIB"
DIM B% 8
TestDate%=FN_today
Line 306 ⟶ 655:
TestDate%+=1
UNTIL VPOS=15
END</langsyntaxhighlight>
{{out}}
<pre>
Line 328 ⟶ 677:
=={{header|C}}==
This only works if time_t is a 64-bit type.
<langsyntaxhighlight lang="c">#include <stdbool.h>
#include <stdio.h>
#include <string.h>
Line 358 ⟶ 707:
}
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 381 ⟶ 730:
 
=={{header|C sharp}}==
<langsyntaxhighlight lang="csharp">using System;
using System.Linq;
using System.Collections.Generic;
Line 402 ⟶ 751:
bool IsValidDate(int y, int m, int d, out DateTime date) => DateTime.TryParse($"{y}-{m}-{d}", out date);
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 423 ⟶ 772:
=={{header|C++}}==
{{libheader|Boost}}
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <string>
#include <boost/date_time/gregorian/gregorian.hpp>
Line 451 ⟶ 800:
}
return 0;
}</langsyntaxhighlight>
 
{{out}}
<pre>
Next 15 palindrome dates:
2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12
</pre>
 
===Using C++20===
<syntaxhighlight lang="c++">
#include <algorithm>
#include <chrono>
#include <iostream>
#include <sstream>
 
bool is_palindrome(const std::chrono::sys_days& date) {
std::ostringstream stream;
stream << date;
std::string date_string = stream.str();
 
date_string.erase(std::remove(date_string.begin(), date_string.end(), '-'), date_string.end());
std::string original = date_string;
std::reverse(date_string.begin(), date_string.end());
 
return date_string == original;
}
 
int main() {
std::chrono::year_month_day date{std::chrono::year{2020}, std::chrono::month{02}, std::chrono::day{02}};
std::chrono::sys_days current_date = std::chrono::sys_days(date);
 
std::cout << "The first 15 palindrome dates after 2020-02-02 are:" << std::endl;
int32_t count = 0;
while ( count < 15 ) {
current_date += std::chrono::days{1};
if ( is_palindrome(current_date) ) {
std::cout << current_date << std::endl;
count++;
}
}
}
</syntaxhighlight>
{{ out }}
<pre>
The first 15 palindrome dates after 2020-02-02 are:
2021-12-02
2030-03-02
Line 474 ⟶ 877:
 
=={{header|Clojure}}==
<syntaxhighlight lang="clojure">
<lang Clojure>
(defn valid-date? [[y m d]]
(and (<= 1 m 12)
Line 492 ⟶ 895:
(map date-str)
(take n)))
</syntaxhighlight>
</lang>
 
{{out}}
Line 498 ⟶ 901:
("2021-12-02" "2030-03-02" "2040-04-02" "2050-05-02" "2060-06-02" "2070-07-02" "2080-08-02" "2090-09-02" "2101-10-12" "2110-01-12" "2111-11-12" "2120-02-12" "2121-12-12" "2130-03-12" "2140-04-12")
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
procedure ShowPalindromeDate(Memo: TMemo);
var DT: TDateTime;
var S,S2: string;
var I,Cnt: integer;
begin
Cnt:=0;
DT:=EncodeDate(2020,02,02);
for I:=0 to High(integer) do
begin
S:=FormatDateTime('yyyymmdd',DT);
S2:=ReverseString(S);
if S=S2 then
begin
Inc(Cnt);
Memo.Lines.Add(IntToStr(Cnt)+' '+FormatDateTime('yyyy-mm-dd',DT));
if Cnt>15 then break;
end;
DT:=DT+1;
end;
end;
 
</syntaxhighlight>
{{out}}
<pre>
1 2020-02-02
2 2021-12-02
3 2030-03-02
4 2040-04-02
5 2050-05-02
6 2060-06-02
7 2070-07-02
8 2080-08-02
9 2090-09-02
10 2101-10-12
11 2110-01-12
12 2111-11-12
13 2120-02-12
14 2121-12-12
15 2130-03-12
16 2140-04-12
Elapsed Time: 44.090 ms.
 
</pre>
 
 
=={{header|EasyLang}}==
<syntaxhighlight>
t = 1580641200
print "First 15 palindrome dates after 2020-02-02 are:"
repeat
t += 86400
a$ = timestr t
a$[] = strchars substr a$ 1 4 & substr a$ 6 2 & substr a$ 9 2
for i = 1 to 4
if a$[i] <> a$[9 - i]
break 1
.
.
if i = 5
cnt += 1
print substr a$ 1 10
.
until cnt = 15
.
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight Fsharplang="fsharp">// palindrome_dates.fsx
open System
 
Line 529 ⟶ 1,004:
|> Seq.take 15
|> Seq.iter print_date
</syntaxhighlight>
</lang>
{{out}}
<pre>> dotnet fsi palindrome_dates.fsx
Line 552 ⟶ 1,027:
A simple brute force solution that repeatedly increments a timestamp's day by one and checks whether it's a palindrome:
{{works with|Factor|0.99 2020-01-23}}
<langsyntaxhighlight lang="factor">USING: calendar calendar.format io kernel lists lists.lazy
sequences sets ;
 
Line 560 ⟶ 1,035:
[ "-" without dup reverse = ] lfilter ;
 
15 palindrome-dates ltake [ print ] leach</langsyntaxhighlight>
{{out}}
<pre>
Line 582 ⟶ 1,057:
A faster version that directly generates palindromic numbers such as <tt>20200202</tt> and keeps those which are valid dates:
{{works with|Factor|0.99 2020-01-23}}
<langsyntaxhighlight lang="factor">USING: calendar calendar.format continuations io kernel lists
lists.lazy math math.functions math.parser math.ranges sequences ;
 
Line 604 ⟶ 1,079:
 
"10,000th palindrome date after 2020-02-02: " write
10,000 palindrome-dates lnth timestamp>ymd print</langsyntaxhighlight>
{{out}}
<pre>
10,000th palindrome date after 2020-02-02: 1250101-05-21
</pre>
 
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
Dim As String dateTest = ""
Dim As Integer Pal =0, total = 0
Print "Siguientes 15 fechas palindr¢micas al 2020-02-02:"
For anno As Integer = 2021 To 9999
dateTest = Ltrim(Str(anno))
For mes As Integer = 1 To 12
If mes < 10 Then dateTest = dateTest + "0"
dateTest += Ltrim(Str(mes))
For dia As Integer = 1 To 31
If mes = 2 And dia > 28 Then Exit For
If (mes = 4 Or mes = 6 Or mes = 9 Or mes = 11) And dia > 30 Then Exit For
If dia < 10 Then dateTest += "0"
dateTest = dateTest + Ltrim(Str(dia))
For Pal = 1 To 4
If Mid(dateTest, Pal, 1) <> Mid(dateTest, 9 - Pal, 1) Then Exit For
Next Pal
If Pal = 5 Then
total += 1
If total <= 15 Then Print Left(dateTest,4);"-";Mid(dateTest,5,2);"-";Right(dateTest,2)
End If
if total > 15 then Exit For : Exit For : Exit For
dateTest = Left(dateTest, 6)
Next dia
dateTest = Left(dateTest, 4)
Next mes
dateTest = ""
Next anno
Sleep
</syntaxhighlight>
{{out}}
<pre>
Siguientes 15 fechas palindrómicas al 2020-02-02:
2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12
</pre>
 
 
=={{header|Go}}==
Simple brute force as speed is not an issue here.
<langsyntaxhighlight lang="go">package main
 
import (
Line 644 ⟶ 1,172:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 665 ⟶ 1,193:
</pre>
Or, a more ambitious version.
<langsyntaxhighlight lang="go">package main
 
import (
Line 726 ⟶ 1,254:
}
fmt.Println()
}</langsyntaxhighlight>
 
{{out}}
Line 746 ⟶ 1,274:
 
=={{header|Haskell}}==
<syntaxhighlight lang ="haskell">import Data.Time.CalendarList (Day, fromGregorianValidunfoldr)
import Data.List.Split (chunksOf)
import Data.List (unfoldr)
import Data.Tuple (swap)
import Data.Bool (bool)
import Data.Maybe (mapMaybe)
import Data.Time.Calendar (Day, fromGregorianValid)
import Data.Tuple (swap)
 
-------------------- PALINDROMIC DATES -------------------
 
palinDates :: [Day]
Line 759 ⟶ 1,288:
palinDay y = fromGregorianValid y m d
where
[m, d] = unDigits <$> chunksOf 2 (reversedDecimalDigits (fromInteger y))
(reversedDecimalDigits (fromInteger y))
 
reversedDecimalDigits :: Int -> [Int]
reversedDecimalDigits =
unfoldr ((flip bool Nothing . Just . swap . flip quotRem 10) <*> (0 ==))
 
unDigits :: [Int] -> Int
unDigits = foldl ((+) . (10 *)) 0
 
--------------------------- TEST -------------------------
main :: IO ()
main = do
let n = length palinDates
in putStrLn $ ("Count of palindromic dates [2021..9999]: " ++ show n
<> show n) >>
putStrLn "\nFirst 15:"
putStrLn "\nFirst 15:" >>
mapM_ print $ take 15 palinDates
mapM_ print (take 15 palinDates) >>
putStrLn "\nLast 15:"
putStrLn "\nLast 15:" >>
mapM_ print $ take 15 (drop (n - 15) palinDates)</lang>
mapM_ print (take 15 (drop (n - 15) palinDates))
 
 
------------------------- GENERIC ------------------------
 
reversedDecimalDigits :: Int -> [Int]
reversedDecimalDigits = unfoldr go
where
go n
| 0 < n = Just $ swap (quotRem n 10)
| otherwise = Nothing
 
unDigits :: [Int] -> Int
unDigits = foldl ((+) . (10 *)) 0</syntaxhighlight>
{{Out}}
<pre>Count of palindromic dates [2021..9999]: 284
Line 812 ⟶ 1,351:
9280-08-29
9290-09-29</pre>
 
=={{header|J}}==
Using J's [[j:Standard_Library/dates|date routines]]:
<syntaxhighlight lang=J>task=: {{
r=. ''
days=. todayno 2020 02 02
while. 15 > #r do.
days=. ({:days)+1+i.1e4
r=. r, days#~(-:|.)"1":,.1 todate days
end.
15 10{.isotimestamp todate r
}}</syntaxhighlight>
 
<syntaxhighlight lang=J> task''
2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12
</syntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
Line 835 ⟶ 1,404:
 
}
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 858 ⟶ 1,427:
=={{header|Javascript}}==
===Procedural===
<langsyntaxhighlight lang="javascript">/**
* Adds zeros for 1 digit days/months
* @param date: string
Line 901 ⟶ 1,470:
}
 
getPalindromeDates();</langsyntaxhighlight>
{{Out}}
<pre>2021-12-02 ​
Line 919 ⟶ 1,488:
2140-04-12 ​</pre>
===Functional===
<langsyntaxhighlight lang="javascript">(() => {
'use strict';
 
Line 975 ⟶ 1,544:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre>Count of palindromic dates [2021..9999]: 284
Line 1,012 ⟶ 1,581:
9280-08-29
9290-09-29</pre>
 
=={{header|jq}}==
'''Adapted from [[#Wren|Wren]]'''
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq'''
 
'''Also works with fq, a Go implementation of a large subset of jq'''
<syntaxhighlight lang=jq>
# input and output: [year, month, day] using month=1 for Jan
# add the number of days to the input date
def addDays($days):
. as [$y,$m,$d]
| [$y,$m-1,$d + $days,0,0,0,0,0] | mktime | gmtime[0:3] | .[1]+=1;
 
# input: [year, month, day], an array of integers
# output: [yyyy, mm, dd] , an array of strings,
def yyyymmdd:
def l($len): tostring | ($len - length) as $l | ("0" * $l)[:$l] + .;
[(.[0]|l(4)), (.[1]|l(2)), (.[2]|l(2))] ;
# input: [year, month, day] using month=1 for Jan
def isPalDate:
yyyymmdd | add | explode | . == reverse;
 
def task:
"The next 15 palindromic dates in yyyy-mm-dd format after 2020-02-02 are:",
( [2020, 2, 2]
| addDays(1)
| limit(15; recurse(addDays(1)) | select(isPalDate) )
| yyyymmdd
| join("-") );
 
task
</syntaxhighlight>
{{output}}
As for [[#Wren|Wren]].
 
 
=={{header|Julia}}==
Uses the built-in Dates package to check date validity but not for iteration.
<langsyntaxhighlight lang="julia">using Dates
function datepalindromes(nextcount=20)
Line 1,038 ⟶ 1,644:
datepalindromes()
</langsyntaxhighlight>{{out}}
<pre>
Date palindromes:
Line 1,062 ⟶ 1,668:
2190-09-12
</pre>
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">
 
local year = 2020
for i=1, 15 do
local dateS
repeat
year = year+1
local yearS = tostring(year)
local monthS, dayS = yearS:reverse():match"^(%d%d)(%d%d)$"
local monthN, dayN = tonumber(monthS), tonumber(dayS)
dateS = yearS.."-"..monthS.."-"..dayS
until
monthN>0 and monthN<=12 -- real month
and dayN<32 -- possible day
and os.date( -- real date check
-- be aware that this check is unnecessary because it only affects the 13th century
"%Y-%m-%d"
,os.time{
year = year
,month = monthN
,day = dayN
}
) == dateS
print(dateS)
end
 
</syntaxhighlight>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">today = DateList[Today];
res = {};
i = 0;
While[Length[res] < 15,
date = DatePlus[today, i];
ds = DateString[date, {"Year", "Month", "Day"}];
If[PalindromeQ[ds],
AppendTo[res, date]
];
i++;
]
Column[DateString[#, {"Year", "-", "Month", "-", "Day"}] & /@ res]</syntaxhighlight>
{{out}}
<pre>2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">import strformat, times
 
func digits(n: int): seq[int] =
var n = n
while n != 0:
result.add n mod 10
n = n div 10
 
echo "First 15 palindrome dates after 2020-02-02:"
var count = 0
var year = 2021
while count != 15:
let d = year.digits
let monthNum = 10 * d[0] + d[1]
let dayNum = 10 * d[2] + d[3]
if monthNum in 1..12:
if dayNum <= getDaysInMonth(Month(monthNum), year):
# Date is valid.
echo &"{year}-{monthNum:02}-{dayNum:02}"
inc count
inc year</syntaxhighlight>
 
{{out}}
<pre>First 15 palindrome dates after 2020-02-02:
2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12</pre>
 
=={{header|Perl}}==
===Date calculation===
The more robust solution, using a date/time module.
<langsyntaxhighlight lang="perl">use Time::Piece;
my $d = Time::Piece->strptime("2020-02-02", "%Y-%m-%d");
 
Line 1,074 ⟶ 1,780:
print $d->strftime("%Y-%m-%d\n");
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,097 ⟶ 1,803:
Given the limited look-ahead required by the task, processing date-like strings can also work.
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 1,112 ⟶ 1,818:
say s/ /-/gr;
last if 15 == ++$cnt;
}</langsyntaxhighlight>
{{out}}
<pre>2021-12-02
Line 1,131 ⟶ 1,837:
 
=={{header|Phix}}==
Note thatWhile parse_date_string() copes with 1/2/4 digit years, butit (reasonably enough) throws a wobbly given 5-digit years and beyond.
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>include builtins\timedate.e
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
sequence res = {}
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
for d=2021 to 9999 do
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
string s = sprintf("%4d",d),
<span style="color: #008080;">for</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2021</span> <span style="color: #008080;">to</span> <span style="color: #000000;">9999</span> <span style="color: #008080;">do</span>
t = reverse(s)
<span style="color: #004080;">string</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%4d"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">),</span>
s &= "-"&t[1..2]&"-"&t[3..4]
<span style="color: #000000;">t</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">reverse</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
sequence td = parse_date_string(s, {"YYYY-MM-DD"})
<span style="color: #000000;">s</span> <span style="color: #0000FF;">&=</span> <span style="color: #008000;">"-"</span><span style="color: #0000FF;">&</span><span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]&</span><span style="color: #008000;">"-"</span><span style="color: #0000FF;">&</span><span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">3</span><span style="color: #0000FF;">..</span><span style="color: #000000;">4</span><span style="color: #0000FF;">]</span>
if timedate(td) then res = append(res,s) end if
<span style="color: #004080;">sequence</span> <span style="color: #000000;">td</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">parse_date_string</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"YYYY-MM-DD"</span><span style="color: #0000FF;">})</span>
end for
<span style="color: #008080;">if</span> <span style="color: #004080;">timedate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">td</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
printf(1,"Count of palindromic dates [2021..9999]: %d\n\n",length(res))
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
printf(1,"first 15:\n%s\n",join_by(res[1..15],3,5))
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Count of palindromic dates [2021..9999]: %d\n\n"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">))</span>
printf(1,"last 15:\n%s\n",join_by(res[-15..-1],3,5))</lang>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"first 15:\n%s\n"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">15</span><span style="color: #0000FF;">],</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">))</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"last 15:\n%s\n"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">[-</span><span style="color: #000000;">15</span><span style="color: #0000FF;">..-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">],</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">))</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 1,157 ⟶ 1,866:
9180-08-19 9210-01-29 9221-12-29 9250-05-29 9280-08-29
9190-09-19 9211-11-29 9230-03-29 9260-06-29 9290-09-29
</pre>
 
=={{header|PureBasic}}==
<syntaxhighlight lang="purebasic">NewList pdates.s()
 
Procedure.b IsLeap(y.i)
ProcedureReturn Bool( y % 4 = 0 ) & Bool( y % 100 <> 0 ) | Bool( y % 400 = 0 )
EndProcedure
 
If OpenConsole("")=0 : End 1 : EndIf
 
For j=2021 To 9999
For m=1 To 12
tm2=28+1*IsLeap(j)
For t=1 To 31
If m=2 And t>tm2 : Break : EndIf
If (m=4 Or m=6 Or m=9 Or m=11) And t>30 : Break : EndIf
s$=Str(j)+RSet(Str(m),2,"0")+RSet(Str(t),2,"0")
If ReverseString(s$)=s$
AddElement(pdates()) : pdates()=Mid(s$,1,4)+"-"+Mid(s$,5,2)+"-"+Mid(s$,7,2)
EndIf
Next t
Next m
Next j
 
PrintN("Count of palindromic dates [2021..9999]: "+Str(ListSize(pdates())))
FirstElement(pdates())
t$="First 15:"
For x=1 To 2
PrintN(~"\n"+t$)
For y=1 To 15 : PrintN(pdates()) : NextElement(pdates()) : Next
t$="Last 15:" : SelectElement(pdates(),ListSize(pdates())-15)
Next
Input() : End</syntaxhighlight>
{{out}}
<pre>Count of palindromic dates [2021..9999]: 284
 
First 15:
2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12
 
Last 15:
9170-07-19
9180-08-19
9190-09-19
9201-10-29
9210-01-29
9211-11-29
9220-02-29
9221-12-29
9230-03-29
9240-04-29
9250-05-29
9260-06-29
9270-07-29
9280-08-29
9290-09-29
</pre>
 
Line 1,163 ⟶ 1,942:
Defined in terms of string reversal:
{{Works with|Python|3.7}}
<langsyntaxhighlight lang="python">'''Palindrome dates'''
 
from datetime import datetime
Line 1,205 ⟶ 1,984:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>Count of palindromic dates [2021..9999]:
Line 1,247 ⟶ 2,026:
Or, defined in terms of integer operations, rather than string reversals:
{{Works with|Python|3.7}}
<langsyntaxhighlight lang="python">'''Palindrome dates'''
 
from functools import reduce
Line 1,374 ⟶ 2,153:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>Count of palindromic dates [2021..9999]:
Line 1,412 ⟶ 2,191:
9280-08-29
9290-09-29</pre>
 
=={{header|QB64}}==
<syntaxhighlight lang=" qb64">
'Task
' Write a program which calculates and shows the next 15 palindromic dates
' for those countries which express their dates in the yyyy-mm-dd format
' and for those countries which express their dates int dd-mm-yyyy format
' the user will choose what format to use for calculating
Dim dateTest As String, Mounth As Integer, Day As Integer, Year As Integer, Pal As Integer, choice As Integer
dateTest = ""
Mounth = 0
Day = 0
Year = 0
Pal = 0
choice = 0
Print " choose date format:"
Print " press 1 for using YYYY-MM-DD format"
Print " press 2 for using DD-MM-YYYY format"
 
While choice < 1 Or choice > 2
choice = Val(InKey$)
Wend
Print " Well, you have choosen format number "; choice
Sleep 2
For Year = 2020 To 2420
dateTest = LTrim$(Str$(Year))
For Mounth = 1 To 12
If Mounth < 10 Then k$ = "0" Else k$ = ""
 
If choice = 1 Then
dateTest = dateTest + k$ + LTrim$(Str$(Mounth))
Else
dateTest = k$ + LTrim$(Str$(Mounth)) + dateTest
End If
 
 
For Day = 1 To 31
If Mounth = 2 And Day > 28 Then Exit For
If (Mounth = 4 Or Mounth = 6 Or Mounth = 9 Or Mounth = 11) And Day > 30 Then Exit For
If Day < 10 Then k$ = "0" Else k$ = ""
If choice = 1 Then
dateTest = dateTest + k$ + LTrim$(Str$(Day))
Else
dateTest = k$ + LTrim$(Str$(Day)) + dateTest
End If
'Print dateTest: Sleep
For Pal = 1 To 4
If Mid$(dateTest, Pal, 1) <> Mid$(dateTest, 9 - Pal, 1) Then Exit For
Next
If Pal = 5 Then Print dateTest
If choice = 1 Then
dateTest = Left$(dateTest, 6)
Else
dateTest = Right$(dateTest, 6)
End If
Next
If choice = 1 Then
dateTest = Left$(dateTest, 4)
Else
dateTest = Right$(dateTest, 4)
End If
Next
dateTest = ""
Next
 
</syntaxhighlight>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ dup 400 mod 0 = iff
[ drop true ] done
dup 100 mod 0 = iff
[ drop false ] done
4 mod 0 = ] is leap ( y --> b )
 
[ 1 -
[ table
31 [ dup leap 28 + ]
31 30 31 30 31 31 30
31 30 31 ]
do nip ] is monthdays ( y m --> n )
 
[ 1+ dip [ 2dup monthdays ]
tuck < while
drop 1+ 1
over 13 = if
[ 2drop 1+ 1 1 ] ] is nextday ( y m d --> y m d )
 
 
[ dip 2dup dup dip unrot ] is 3dup ( a b c --> a b c a b c )
 
[ swap 100 * +
swap 10000 * +
number$ ] is date$ ( y m d --> $ )
 
[ dup reverse = ] is palindrome ( $ --> b )
 
[ char - swap 4 stuff
char - swap 7 stuff ] is +dashes ( $ --> $ )
 
[] temp put
2020 02 02
[ nextday
3dup date$
dup palindrome iff
[ temp take
swap nested join
temp put ]
else drop
temp share
size 15 = until ]
drop 2drop
temp take witheach
[ +dashes echo$ cr ]</syntaxhighlight>
 
{{out}}
 
<pre>2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12
</pre>
 
 
=={{header|Raku}}==
Line 1,418 ⟶ 2,331:
Pretty basic, but good enough. Could start earlier but 3/2/1 digit years require different handling that isn't necessary for this task. (And would be pretty pointless anyway assuming we need 2 digits for the month and two digits for the day. ISO:8601 anybody?)
 
<syntaxhighlight lang="raku" perl6line>my $start = '1000-01-01';
my @palindate = {
Line 1,442 ⟶ 2,355:
 
say "\nTotal number of five digit year palindrome dates:\n" ~
+@palindate[$four .. $five]</langsyntaxhighlight>
{{out}}
<pre>2020-02-02
Line 1,473 ⟶ 2,386:
The &nbsp; '''date''' &nbsp; BIF &nbsp; (with the &nbsp; '''base''' &nbsp; argument) &nbsp; converts a date to the number of years since the beginning of
<br>the Gregorian calendar, &nbsp; the date is in the &nbsp; '''ISO''' &nbsp; format &nbsp; (International Standards Organization &nbsp; 8601:2004).
<langsyntaxhighlight lang="rexx">/*REXX program finds & displays the next N palindromic dates starting after 2020─02─02*/
/* ───── */
parse arg n from . /*obtain optional argumets from the CL*/
Line 1,485 ⟶ 2,398:
say 'a palindromic date: ' aDate /*display a palindromic date ──► term. */
#= # + 1 /*bump the counter of palindromic dates*/
end /*j*/ /*stick a fork in it, we're all done. */</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 1,503 ⟶ 2,416:
a palindromic date: 2130-03-12
a palindromic date: 2140-04-12
</pre>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
load "stdlib.ring"
 
dt = 0
num = 0
limit = 15
 
? "First 15 palindromic dates:" + nl
 
while num < limit
 
dt++
dateStr = adddays(date(),dt)
newDate = substr(dateStr,7,4) + substr(dateStr,4,2) + substr(dateStr,1,2)
newDate2 = substr(dateStr,7,4) + "-" + substr(dateStr,4,2) + "-" + substr(dateStr,1,2)
if ispalindrome(newDate)
num++
? newDate2
ok
if num > limit
exit
ok
 
end
</syntaxhighlight>
{{out}}
<pre>
First 15 palindromic dates:
 
2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12
</pre>
 
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
≪ DUP 100 MOD 4 400 IFTE MOD NOT ≫
‘'''LEAP?'''’ STO
≪ 100 + →STR 2 3 SUB ≫
‘'''→2STR'''’ STO
≪ STR→ → mm dd yy
≪ mm 1 ≥ mm 12 ≤ AND
IF DUP
THEN
{ 31 28 31 30 31 30 31 31 30 31 30 31 }
IF yy '''LEAP?''' THEN 2 29 PUT END
mm GET dd ≥ AND dd 1 ≥ AND
END
≫ ≫
‘'''DTOK?'''’ STO
≪ →STR → year
≪ year 4 DUP SUB year 3 DUP SUB + STR→
year 2 DUP SUB year 1 DUP SUB + STR→
IF DUP2 year '''DTOK?'''
THEN year "-" + ROT '''→2STR''' + "-" + SWAP '''→2STR''' +
ELSE DROP2 ""
END
≫ ≫
‘'''PALDT'''’ STO
 
≪ { } 2023
WHILE OVER SIZE 15 < REPEAT
DUP '''PALDT'''
IF DUP "" ≠ THEN ROT SWAP + SWAP ELSE DROP END
1 +
END
DROP
EVAL
{{out}}
<pre>
1: { "2030-03-02" "2040-04-02" "2050-05-02" "2060-06-02" "2070-07-02"
"2080-08-02" "2090-09-02" "2101-10-12" "2110-01-12" "2111-11-12"
"2120-02-12" "2121-12-12" "2130-03-12" "2140-04-12" "2150-05-12" }
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">require 'date'
 
palindate = Enumerator.new do |yielder|
Line 1,516 ⟶ 2,521:
end
 
puts palindate.take(15)</langsyntaxhighlight>
{{out}}
<pre>
Line 1,537 ⟶ 2,542:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">// [dependencies]
// chrono = "0.4"
 
Line 1,554 ⟶ 2,559:
date = date.succ();
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,578 ⟶ 2,583:
=={{header|Sidef}}==
{{trans|Ruby}}
<langsyntaxhighlight lang="ruby">var palindates = gather {
for y in (2020 .. 9999) {
var (m, d) = Str(y).flip.last(4).split(2)...
Line 1,594 ⟶ 2,599:
]) {
say ("\n#{a}\n", b.slices(5).map { .join(" ") }.join("\n"))
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,608 ⟶ 2,613:
9211-11-29 9220-02-29 9221-12-29 9230-03-29 9240-04-29
9250-05-29 9260-06-29 9270-07-29 9280-08-29 9290-09-29
</pre>
 
=={{header|Swift}}==
<syntaxhighlight lang="swift">import Foundation
 
func isPalindrome(_ string: String) -> Bool {
let chars = string.lazy
return chars.elementsEqual(chars.reversed())
}
 
let format = DateFormatter()
format.dateFormat = "yyyyMMdd"
 
let outputFormat = DateFormatter()
outputFormat.dateFormat = "yyyy-MM-dd"
 
var count = 0
let limit = 15
let calendar = Calendar.current
var date = Date()
 
while count < limit {
if isPalindrome(format.string(from: date)) {
print(outputFormat.string(from: date))
count += 1
}
date = calendar.date(byAdding: .day, value: 1, to: date)!
}</syntaxhighlight>
 
{{out}}
Output when executed on 2020-07-26:
<pre>
2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12
</pre>
 
=={{header|UNIX Shell}}==
printf format, rev and date commands are the keys :
<langsyntaxhighlight lang="shell">is_palyndrom_date() { date -d "$1" 1>/dev/null 2>&1 && echo "$1" ; }
 
for _H in {2..9}; do
Line 1,621 ⟶ 2,673:
done
done
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,643 ⟶ 2,695:
2130-03-12
...
</pre>
 
=={{header|VBA}}==
<syntaxhighlight lang="vb">
Sub MainPalindromeDates()
Const FirstDate As String = "2020-02-02"
Const NumberOfDates As Integer = 15
Dim D As String, temp As String, Cpt As Integer
temp = Format(DateAdd("d", 1, CDate(FirstDate)), "yyyy-mm-dd")
Do
D = Replace(temp, "-", "")
If IsDatePalindrome(D) Then
Debug.Print Left(D, 4) & "-" & Mid(D, 5, 2) & "-" & Right(D, 2)
Cpt = Cpt + 1
End If
temp = Format(DateAdd("d", 1, CDate(temp)), "yyyy-mm-dd")
Loop While Cpt < NumberOfDates
End Sub
Function IsDatePalindrome(strDate As String) As Boolean
IsDatePalindrome = StrReverse(Left(strDate, 4)) = Right(strDate, 4)
End Function
</syntaxhighlight>
 
{{out}}The next 15 palindromic dates in yyyy-mm-dd format after 2020-02-02 are :
<pre>2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12
</pre>
 
Line 1,648 ⟶ 2,739:
{{libheader|Wren-fmt}}
{{libheader|Wren-date}}
<langsyntaxhighlight ecmascriptlang="wren">import "./fmt" for Fmt
import "./date" for Date
 
var isPalDate = Fn.new { |date|
Line 1,666 ⟶ 2,757:
count = count + 1
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,687 ⟶ 2,778:
2140-04-12
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">func Rev(N);
int N;
[N:= N/10;
return rem(0)*10 + N;
];
 
proc NumOut(N);
int N;
[if N < 10 then ChOut(0, ^0);
IntOut(0, N);
];
 
int C, Y, M, D, Q, R;
[C:= 0;
for Y:= 2021 to -1>>1 do
for M:= 1 to 12 do
for D:= 1 to 28 do
[Q:= Y/100;
R:= rem(0);
if Q = Rev(D) and R = Rev(M) then
[IntOut(0, Y); ChOut(0, ^-);
NumOut(M); ChOut(0, ^-);
NumOut(D); CrLf(0);
C:= C+1;
if C >= 15 then return;
];
];
]</syntaxhighlight>
 
{{out}}
<pre>
2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12
</pre>
 
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="yabasic">
dateTest$ = ""
total = 0
print "Siguientes 15 fechas palindr¢micas al 2020-02-02:"
for anno = 2021 to 9999
dateTest$ = ltrim$(str$(anno))
for mes = 1 to 12
if mes < 10 then dateTest$ = dateTest$ + "0" : fi
dateTest$ = dateTest$ + ltrim$(str$(mes))
for dia = 1 to 31
if mes = 2 and dia > 28 then break : fi
if (mes = 4 or mes = 6 or mes = 9 or mes = 11) and dia > 30 then break : fi
if dia < 10 then dateTest$ = dateTest$ + "0" : fi
dateTest$ = dateTest$ + ltrim$(str$(dia))
for Pal = 1 to 4
if mid$(dateTest$, Pal, 1) <> mid$(dateTest$, 9 - Pal, 1) then break : fi
next Pal
if Pal = 5 then
total = total + 1
if total <= 15 then print left$(dateTest$,4),"-",mid$(dateTest$,5,2),"-",right$(dateTest$,2) : fi
end if
if total > 15 then break : break : break : fi
dateTest$ = left$(dateTest$, 6)
next dia
dateTest$ = left$(dateTest$, 4)
next mes
dateTest$ = ""
next anno
end
</syntaxhighlight>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">TD,date,n := Time.Date, T(2020,02,02), 15;
while(n){
ds:=TD.toYMDString(date.xplode()) - "-";
if(ds==ds.reverse()){ n-=1; println(TD.toYMDString(date.xplode())); }
date=TD.addYMD(date,0,0,1);
}</langsyntaxhighlight>
{{out}}
<pre>
1,983

edits