Date format: Difference between revisions

55,020 bytes added ,  29 days ago
(121 intermediate revisions by 51 users not shown)
Line 5:
Display the   current date   in the formats of:
:::*   '''2007-11-23'''     and
:::*   '''SundayFriday, November 23, 2007'''
<br><br>
 
=={{header|11l}}==
<syntaxhighlight lang="11l">print(Time().format(‘YYYY-MM-DD’))
print(Time().strftime(‘%A, %B %e, %Y’))</syntaxhighlight>
 
=={{header|68000 Assembly}}==
{{works with|NEOGEO MVS}}
This code only works on the arcade system, not the home consoles, because only the arcade system has a built-in system clock. which can be read using <code>JSR $C0045C</code>. MAME uses your computer's date and time as the source for this data. The code below runs in-line and uses a few macros and labels, but they are mostly self-explanatory. The code required to set up the palettes and print characters to the screen has been omitted for brevity, but is fully implemented.
 
<syntaxhighlight lang="68000devpac"> JSR SYS_READ_CALENDAR ;outputs calendar date to BIOS RAM
 
MOVE.B #'2',D0 ;a character in single or double quotes refers to its ascii equivalent.
JSR PrintChar
MOVE.B #'0',D0
JSR PrintChar
LEA BIOS_YEAR,A1
MOVE.B (A1)+,D0 ;stores last 2 digits of year into D0, in binary coded decimal
JSR UnpackNibbles8 ;separate the digits into high and low nibbles: D0 = 00020001
ADD.L #$00300030,D0 ;convert both numerals to their ascii equivalents.
SWAP D0 ;print the "2" first
JSR PrintChar
SWAP D0 ;then the "1"
JSR PrintChar
MOVE.B #'-',D0
JSR PrintChar
MOVE.B (A1)+,D0 ;get the month
JSR UnpackNibbles8
ADD.L #$00300030,D0
SWAP D0
JSR PrintChar
SWAP D0
JSR PrintChar
MOVE.B #'-',D0
JSR PrintChar
MOVE.B (A1)+,D0 ;get the day
JSR UnpackNibbles8
ADD.L #$00300030,D0
SWAP D0
JSR PrintChar
SWAP D0
JSR PrintChar
;now the date is printed.
;Now do it again only written out:
jsr NewLine
CLR.L D0 ;reset D0
MOVE.B (A1),D0 ;A1 happens to point to the weekday
LSL.W #2,D0 ;we are indexing into a table of longs
LEA Days_Lookup,A2
LEA (A2,D0),A2
MOVEA.L (A2),A3 ;dereference the pointer into A3, which the PrintString routine takes as an argument.
JSR PrintString
CLR.L D0
LEA BIOS_MONTH,A1 ;GET THE MONTH
MOVE.B (A1)+,D0
LSL.W #2,D0
LEA Months_Lookup,A2
LEA (A2,D0),A2
MOVEA.L (A2),A3
JSR PrintString
MOVE.B (A1),D0 ;GET THE DAY
JSR UnpackNibbles8
ADD.L #$00300030,D0
SWAP D0
JSR PrintChar
SWAP D0
JSR PrintChar
MOVE.B #',',D0
JSR PrintChar
MOVE.B #' ',D0
JSR PrintChar
MOVE.B #'2',D0
JSR PrintChar
MOVE.B #'0',D0
JSR PrintChar
LEA BIOS_YEAR,A1
MOVE.B (A1)+,D0 ;stores last 2 digits of year into D0, in binary coded decimal
JSR UnpackNibbles8 ;separate the digits into high and low nibbles: D0 = 00020001
ADD.L #$00300030,D0 ;convert both numerals to their ascii equivalents.
SWAP D0 ;print the "2" first
JSR PrintChar
SWAP D0 ;then the "1"
JSR PrintChar
 
forever:
bra forever ;trap the program counter
 
UnpackNibbles8:
; INPUT: D0 = THE VALUE YOU WISH TO UNPACK.
; HIGH NIBBLE IN HIGH WORD OF D0, LOW NIBBLE IN LOW WORD. SWAP D0 TO GET THE OTHER HALF.
pushWord D1
CLR.W D1
MOVE.B D0,D1
CLR.L D0
MOVE.B D1,D0 ;now D0 = D1 = $000000II, where I = input
AND.B #$F0,D0 ;chop off bottom nibble
LSR.B #4,D0 ;downshift top nibble into bottom nibble of the word
SWAP D0 ;store in high word
AND.B #$0F,D1 ;chop off bottom nibble
MOVE.B D1,D0 ;store in low word
popWord D1
rts</syntaxhighlight>
 
Output can be seen [https://ibb.co/52Ks0yf here,] but is also reproduced below:
<pre>
2021-09-19
Sunday, September 19, 2021
</pre>
 
=={{header|8th}}==
<langsyntaxhighlight lang="forth">
d:new
"%Y-%M-%D" over d:format . cr
"%W, %N %D, %Y" over d:format . cr
bye
</syntaxhighlight>
</lang>
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program dateFormat64.s */
 
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
.equ GETTIME, 169 // call system linux gettimeofday
/*******************************************/
/* Structures */
/********************************************/
/* example structure time */
.struct 0
timeval_sec: //
.struct timeval_sec + 8
timeval_usec: //
.struct timeval_usec + 8
timeval_end:
.struct 0
timezone_min: //
.struct timezone_min + 8
timezone_dsttime: //
.struct timezone_dsttime + 8
timezone_end:
/*********************************/
/* Initialized data */
/*********************************/
.data
szMessError: .asciz "Error detected !!!!. \n"
szMessResult: .asciz "Date : @/@/@ \n" // message result
szMessResult1: .asciz "Date day : @ @ @ @ \n" // message result
szJan: .asciz "Janvier"
szFev: .asciz "Fèvrier"
szMars: .asciz "Mars"
szAvril: .asciz "Avril"
szMai: .asciz "Mai"
szJuin: .asciz "Juin"
szJuil: .asciz "Juillet"
szAout: .asciz "Aout"
szSept: .asciz "Septembre"
szOct: .asciz "Octobre"
szNov: .asciz "Novembre"
szDec: .asciz "Décembre"
szLundi: .asciz "Lundi"
szMardi: .asciz "Mardi"
szMercredi: .asciz "Mercredi"
szJeudi: .asciz "Jeudi"
szVendredi: .asciz "Vendredi"
szSamedi: .asciz "Samedi"
szDimanche: .asciz "Dimanche"
szCarriageReturn: .asciz "\n"
.align 4
tbDayMonthYear: .quad 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335
.quad 366, 397, 425, 456, 486, 517, 547, 578, 609, 639, 670, 700
.quad 731, 762, 790, 821, 851, 882, 912, 943, 974,1004,1035,1065
.quad 1096,1127,1155,1186,1216,1247,1277,1308,1339,1369,1400,1430
tbMonthName: .quad szJan
.quad szFev
.quad szMars
.quad szAvril
.quad szMai
.quad szJuin
.quad szJuil
.quad szAout
.quad szSept
.quad szOct
.quad szNov
.quad szDec
tbDayName: .quad szLundi
.quad szMardi
.quad szMercredi
.quad szJeudi
.quad szVendredi
.quad szSamedi
.quad szDimanche
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
.align 4
stTVal: .skip timeval_end
stTZone: .skip timezone_end
sZoneConv: .skip 24
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: // entry of program
ldr x0,qAdrstTVal
ldr x1,qAdrstTZone
mov x8,#GETTIME
svc 0
cmp x0,#-1 // error ?
beq 99f
ldr x1,qAdrstTVal
ldr x0,[x1,#timeval_sec] // timestamp in second
bl dateFormatNum
ldr x0,[x1,#timeval_sec] // timestamp in second
bl dateFormatAlpha
ldr x0,qTStest1
bl dateFormatNum
ldr x0,qTStest1
bl dateFormatAlpha
ldr x0,qTStest2
bl dateFormatNum
ldr x0,qTStest2
bl dateFormatAlpha
ldr x0,qTStest3
bl dateFormatNum
ldr x0,qTStest3
bl dateFormatAlpha
b 100f
99:
ldr x0,qAdrszMessError
bl affichageMess
100: // standard end of the program
mov x0,#0 // return code
mov x8,#EXIT // request to exit program
svc 0 // perform the system call
qAdrszMessError: .quad szMessError
qAdrstTVal: .quad stTVal
qAdrstTZone: .quad stTZone
qAdrszCarriageReturn: .quad szCarriageReturn
qAdrsZoneConv: .quad sZoneConv
qTStest1: .quad 1609508339 // 01/01/2021
qTStest2: .quad 1657805939 // 14/07/2022
qTStest3: .quad 1767221999 // 31/12/2025
/******************************************************************/
/* date format numeric */
/******************************************************************/
/* x0 contains the timestamp in seconds */
dateFormatNum:
stp x1,lr,[sp,-16]! // save registers
ldr x2,qSecJan2020
sub x0,x0,x2 // total secondes to 01/01/2020
mov x1,60
udiv x0,x0,x1 // divide secondes
udiv x0,x0,x1 // divide minutes
mov x1,#24
udiv x0,x0,x1 // divide hours
mov x11,x0
mov x1,#(365 * 4 + 1)
udiv x9,x0,x1
lsl x9,x9,#2 // multiply by 4 = year1
mov x1,#(365 * 4 + 1)
udiv x2,x11,x1
msub x10,x2,x1,x11
ldr x1,qAdrtbDayMonthYear
mov x2,#3
mov x3,#12
1:
mul x11,x3,x2
ldr x4,[x1,x11,lsl 3] // load days by year
cmp x10,x4
bge 2f
sub x2,x2,1
cbnz x2,1b
2: // x2 = year2
mov x5,11
mul x11,x3,x2
lsl x11,x11,3
add x11,x11,x1 // table address
3:
ldr x4,[x11,x5,lsl 3] // load days by month
cmp x10,x4
bge 4f
subs x5,x5,1
bne 3b
4: // x5 = month - 1
mul x11,x3,x2
add x11,x11,x5
ldr x1,qAdrtbDayMonthYear
ldr x3,[x1,x11,lsl 3]
sub x0,x10,x3
add x0,x0,1 // final compute day
ldr x1,qAdrsZoneConv
bl conversion10 // this function do not zero final
ldr x0,qAdrszMessResult
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at first // character
mov x3,x0
add x0,x5,1 // final compute month
cmp x0,12
sub x1,x0,12
csel x0,x1,x0,gt
ldr x1,qAdrsZoneConv
bl conversion10
mov x0,x3
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at next // character
mov x3,x0
ldr x11,qYearStart
add x0,x9,x11
add x0,x0,x2 // final compute year = 2020 + yeax1 + yeax2
ldr x1,qAdrsZoneConv
bl conversion10
mov x0,x3
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at next // character
bl affichageMess
100:
ldp x1,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
qAdrszMessResult: .quad szMessResult
/******************************************************************/
/* date format alphanumeric */
/******************************************************************/
/* x0 contains the timestamp in seconds */
dateFormatAlpha:
stp x1,lr,[sp,-16]! // save registers
ldr x2,qSecJan2020
sub x0,x0,x2 // total secondes to 01/01/2020
mov x6,x0
mov x1,60
udiv x0,x0,x1
udiv x0,x0,x1
mov x1,24
udiv x0,x0,x1
mov x7,x0
mov x1,(365 * 4 + 1)
udiv x9,x0,x1
lsl x9,x9,#2 // multiply by 4 = year1
mov x1,(365 * 4 + 1)
udiv x0,x7,x1
msub x10,x0,x1,x7
ldr x1,qAdrtbDayMonthYear
mov x8,3
mov x3,12
1:
mul x7,x3,x8
ldr x4,[x1,x7,lsl 3] // load days by year
cmp x10,x4
bge 2f
sub x8,x8,1
cmp x8,0
bne 1b
2: // x8 = yeax2
mov x5,#11
mul x7,x3,x8
lsl x7,x7,3
add x7,x7,x1
3:
ldr x4,[x7,x5,lsl 3] // load days by month
cmp x10,x4
bge 4f
subs x5,x5,1
bne 3b
4: // x5 = month - 1
mov x0,x6 // number secondes depuis 01/01/2020
ldr x1,qNbSecByDay
udiv x0,x6,x1
mov x1,7
udiv x2,x0,x1
msub x3,x2,x1,x0
add x2,x3,2
cmp x2,7
sub x3,x2,7
csel x2,x3,x2,ge
ldr x1,qAdrtbDayName
ldr x1,[x1,x2,lsl 3]
ldr x0,qAdrszMessResult1
 
bl strInsertAtCharInc // insert result at next // character
mov x3,x0
mov x7,12
mul x11,x7,x8
add x11,x11,x5
ldr x1,qAdrtbDayMonthYear
ldr x7,[x1,x11,lsl 3]
sub x0,x10,x7
add x0,x0,1 // final compute day
ldr x1,qAdrsZoneConv
bl conversion10 // this function do not zero final
mov x0,x3
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at first // character
mov x3,x0
ldr x1,qAdrtbMonthName
cmp x5,12
sub x2,x5,12
csel x5,x2,x5,ge
ldr x1,[x1,x5,lsl 3] // month name
mov x0,x3
bl strInsertAtCharInc // insert result at first // character
mov x3,x0
ldr x0,qYearStart
add x0,x0,x8
add x0,x0,x9 // final compute year = 2020 + yeax1 + yeax2
ldr x1,qAdrsZoneConv
bl conversion10 // this function do not zero final
mov x0,x3
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at first // character
bl affichageMess
100:
ldp x1,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
qAdrszMessResult1: .quad szMessResult1
qSecJan2020: .quad 1577836800
qAdrtbDayMonthYear: .quad tbDayMonthYear
qYearStart: .quad 2020
qAdrtbMonthName: .quad tbMonthName
qAdrtbDayName: .quad tbDayName
qNbSecByDay: .quad 3600 * 24
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
=={{header|ABAP}}==
<syntaxhighlight lang="abap">
<lang ABAP>
report zdate.
data: lv_month type string,
Line 39 ⟶ 487:
concatenate sy-datum(4) '-' sy-datum+4(2) '-' sy-datum+6(2) into lv_date.
write / lv_date.
</syntaxhighlight>
</lang>
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">DEFINE PTR="CARD"
 
TYPE Date=[
INT year
BYTE month
BYTE day]
 
PTR ARRAY DayOfWeeks(7)
PTR ARRAY Months(12)
 
PROC Init()
DayOfWeeks(0)="Sunday" DayOfWeeks(1)="Monday"
DayOfWeeks(2)="Tuesday" DayOfWeeks(3)="Wednesday"
DayOfWeeks(4)="Thursday" DayOfWeeks(5)="Friday"
DayOfWeeks(6)="Saturday"
Months(0)="January" Months(1)="February"
Months(2)="March" Months(3)="April"
Months(4)="May" Months(5)="June"
Months(6)="July" Months(7)="August"
Months(8)="September" Months(9)="October"
Months(10)="November" Months(11)="December"
RETURN
 
;https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Sakamoto.27s_methods
BYTE FUNC DayOfWeek(Date POINTER d) ;1<=m<=12, y>1752
BYTE ARRAY t=[0 3 2 5 0 3 5 1 4 6 2 4]
BYTE res
INT y
 
y=d.year
IF d.month<3 THEN
y==-1
FI
res=(y+y/4-y/100+y/400+t(d.month-1)+d.day) MOD 7
RETURN (res)
 
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 PrintDateLong(Date POINTER d)
BYTE wd
 
wd=DayOfWeek(d)
Print(DayOfWeeks(wd)) Print(", ")
Print(Months(d.month-1)) Put(' )
PrintB(d.day) Print(", ")
PrintI(d.year)
RETURN
 
PROC Main()
Date d
 
Init()
 
;There is no function to get the current date
;on Atari 8-bit computer
d.year=2021 d.month=9 d.day=1
 
PrintDateShort(d) PutE()
PrintDateLong(d) PutE()
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Date_format.png Screenshot from Atari 8-bit computer]
<pre>
2021-09-01
Wednesday, September 1, 2021
</pre>
 
=={{header|Ada}}==
<langsyntaxhighlight lang="ada">with Ada.Calendar; use Ada.Calendar;
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Text_IO; use Ada.Text_IO;
Line 85 ⟶ 612:
& Year_Number'Image (Ada.Calendar.Year (Today))
);
end Date_Format;</langsyntaxhighlight>
 
{{out}}
Line 91 ⟶ 618:
2008-10-03
Friday, October 3, 2008
</pre>
 
=={{header|Apex}}==
<lang java>
Datetime dtNow = datetime.now();
String strDt1 = dtNow.format('yyyy-MM-dd');
String strDt2 = dtNow.format('EEEE, MMMM dd, yyyy');
system.debug(strDt1); // "2007-11-10"
system.debug(strDt2); //"Sunday, November 10, 2007"
</lang>
 
{{out}}
<pre>
2016-04-20
Wednesday, April 20, 2016
</pre>
 
Line 113 ⟶ 625:
Note: the '''format''' can be used for both printing ''and'' reading date data.
 
<langsyntaxhighlight lang="algol68"># define the layout of the date/time as provided by the call to local time #
STRUCT ( INT sec, min, hour, mday, mon, year, wday, yday, isdst) tm = (6,5,4,3,2,1,7,~,8);
 
Line 135 ⟶ 647:
 
printf((unix time repr, now[wday OF tm], now[mon OF tm], now[mday OF tm],
now[hour OF tm:sec OF tm], now[isdst OF tm]+1, now[year OF tm], $l$))</langsyntaxhighlight>
{{out}}
<pre>
Line 142 ⟶ 654:
Wed Apr 8 18:04:02 MSD 2009
</pre>
 
=={{header|Apex}}==
<syntaxhighlight lang="java">
Datetime dtNow = datetime.now();
String strDt1 = dtNow.format('yyyy-MM-dd');
String strDt2 = dtNow.format('EEEE, MMMM dd, yyyy');
system.debug(strDt1); // "2007-11-10"
system.debug(strDt2); //"Sunday, November 10, 2007"
</syntaxhighlight>
 
{{out}}
<pre>
2016-04-20
Wednesday, April 20, 2016
</pre>
 
=={{header|AppleScript}}==
===Idiomatic===
 
This restores the legitimate code which has twice now been deleted by the poster of the hacks below. Explicitly: square brackets are not and have never been part of the AppleScript language and <tt>«class isot» as string</tt> is a hack someone discovered many years ago when it wasn't possible to coerce AppleScript month enums directly to integer and when AppleScript's <tt>string</tt> class used 8-bit characters. Back then, the coercion from <tt>string</tt> to <tt>«class isot»</tt> also worked. But this ended with the introduction of AppleScript 2.0 in 2007, when <tt>string</tt>, <tt>Unicode text</tt>, and <tt>text</tt> became synonymous terms for UTF-16 text. The ability to coerce from 8-bit text specifically to <tt>string</tt> was retained for compatibility with existing scripts and for reading non-Unicode text files. Other classes of text such <tt>C string</tt> were discontinued.
 
Whether or not they happen to work, to insist on posting code containing things which have never been part of the language without noting them as hacks, when they're entirely unnecessary, and deleting legitimate and effective code to make way for them, is seriously to misinform readers.
 
<syntaxhighlight lang="applescript">set {year:y, month:m, day:d, weekday:w} to (current date)
 
tell (y * 10000 + m * 100 + d) as text to set shortFormat to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8
set longFormat to (w as text) & (", " & m) & (space & d) & (", " & y)
 
return (shortFormat & linefeed & longFormat)</syntaxhighlight>
 
{{output}}
 
<syntaxhighlight lang="applescript">"2020-10-28
Wednesday, October 28, 2020"</syntaxhighlight>
 
===Hack alternative===
AppleScript <code>date</code> objects are very simple to manipulate, provided one is familiar with the slightly unintuitive nature of how they should be handled in order to be robust and produce the desired result across all systems. Despite the official documentation claiming otherwise, AppleScript is not able to parse date strings that don’t strictly adhere to the date and time format strings specified in System Preferences—thus it is a setting that is specific to one’s system, and won’t naturally port. <br/> <br/>
 
AppleScript provides properties and classes specifically for manipulating or constructing date objects that are not dependent on anything outwith the AppleScript language. In most cases, the <code>current date</code> command provides a starting point, from which one gets current or sets new values for its <code>day</code>, <code>month</code>, <code>year</code>, and <code>time</code> properties and property classes to determine or affect the date a particular date object refers to. <br/> <br/>
 
Formatting is usually achieved by extracting individual date components, performing text manipulations (e.g. to prepend leading zeroes) on each of these, then concatenating these for the final result. The <code>«class isot»</code> class doesn’t have a vernacular form and can only be accessed using its raw chevron syntactic form, which others may recognise from similar AppleScript classes such as <code>«class furl»</code>, <code>«class utf8»</code> and so forth. They can provide some useful—and, often, more reliable—features that can save the headache suffered by many when learning how the <code>file</code>, <code>POSIX file</code>, and <code>alias</code> classes differ between one another, and then also with the way the same class can be implemented in ways or yield unexpected results when used in a context specific to a scriptable application. <br/> <br/>
 
<code>«class isot»</code> and <code>date</code> class objects can coerce to and from one another. The <code>«class isot»</code> is an opaque data type wrapping the hexbytes of an ISO-8601 formatted datetime string. Sadly, it doesn’t permit one to use it to convert a string into hexbytes, but it is ideal for taking a <code>date</code> reference via the <code>«class isot»</code> intermediary form and coercing this to <code>string</code> class (whose chevron syntax form is <code>«class TEXT»</code>), but it will '''not''' coerce onto other AppleScript classes that are normally used interchangeably to represent strings, namely <code>text</code> (<code>«class ctxt»</code>) or <code>unicode text</code> (<code>«class utxt»</code>). <br/> <br/>
 
Both scripts provided below, contributed separately by different users, each make use of the features discussed above. The first demonstrates the simplest and most direct solution, but simplicity forces specificity, which limits what other algorithmic problems it could usefully or easily be adapted to solve. The latter borrows a functional approach and favours an initial investment to create the atomic handlers that pay off by providing the reusable building blocks of identical code that will be the composable functions all other scripts are assembled from sparing much of the need to write new code to solve the vast majority of problems on this site. Generality, versatility and adaptability of this approach can be proven mathematically. <br/> <br/>
 
 
 
<syntaxhighlight lang="applescript">tell (the current date)
set shortdate to text 1 thru 10 of (it as «class isot» as string)
set longdate to the contents of [its weekday, ", ", ¬
(its month), " ", day, ", ", year] as text
end tell
 
log the shortdate
log the longdate</syntaxhighlight>
 
{{output}}
<pre>2020-09-11
Friday, September 11, 2020</pre>
 
===Functional===
Or, emphasising productivity and functional composition:
 
<syntaxhighlight lang="applescript">-- iso8601Short :: Date -> String
on iso8601Short(dte)
text 1 thru 10 of iso8601Local(dte)
end iso8601Short
 
 
-- longDate :: Date -> String
on longDate(dte)
tell dte
"" & its weekday & ", " & its month & " " & its day & ", " & year
end tell
end longDate
 
 
---------------------------- TEST --------------------------
on run
unlines(apList({iso8601Short, longDate}, ¬
{current date}))
end run
 
 
-------------------------- GENERIC -------------------------
 
 
-- Each member of a list of functions applied to
-- each of a list of arguments, deriving a list of new values
-- apList (<*>) :: [(a -> b)] -> [a] -> [b]
on apList(fs, xs)
set lst to {}
repeat with f in fs
tell mReturn(contents of f)
repeat with x in xs
set end of lst to |λ|(contents of x)
end repeat
end tell
end repeat
return lst
end apList
 
 
-- iso8601Local :: Date -> String
on iso8601Local(dte)
(dte as «class isot» as string)
end iso8601Local
 
 
-- mReturn :: First-class m => (a -> b) -> m (a -> b)
on mReturn(f)
-- 2nd class handler function lifted into 1st class script wrapper.
if script is class of f then
f
else
script
property |λ| : f
end script
end if
end mReturn
 
 
-- unlines :: [String] -> String
on unlines(xs)
-- A single string formed by the intercalation
-- of a list of strings with the newline character.
set {dlm, my text item delimiters} to ¬
{my text item delimiters, linefeed}
set s to xs as text
set my text item delimiters to dlm
s
end unlines</syntaxhighlight>
{{Out}}
<pre>2020-09-11
Friday, September 11, 2020</pre>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
/* program dateFormat.s */
 
/* REMARK 1 : this program use routines in a include file
see task Include a file language arm assembly
for the routine affichageMess conversion10
see at end of this program the instruction include */
 
/*******************************************/
/* Constantes */
/*******************************************/
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
.equ BRK, 0x2d @ Linux syscall
.equ CHARPOS, '@'
 
.equ GETTIME, 0x4e @ call system linux gettimeofday
 
/*******************************************/
/* Structures */
/********************************************/
/* example structure time */
.struct 0
timeval_sec: @
.struct timeval_sec + 4
timeval_usec: @
.struct timeval_usec + 4
timeval_end:
.struct 0
timezone_min: @
.struct timezone_min + 4
timezone_dsttime: @
.struct timezone_dsttime + 4
timezone_end:
 
/*********************************/
/* Initialized data */
/*********************************/
.data
szMessError: .asciz "Error detected !!!!. \n"
szMessResult: .asciz "Date : @/@/@ \n" @ message result
szMessResult1: .asciz "Date day : @ @ @ @ \n" @ message result
szJan: .asciz "Janvier"
szFev: .asciz "Février"
szMars: .asciz "Mars"
szAvril: .asciz "Avril"
szMai: .asciz "Mai"
szJuin: .asciz "Juin"
szJuil: .asciz "Juillet"
szAout: .asciz "Aout"
szSept: .asciz "Septembre"
szOct: .asciz "Octobre"
szNov: .asciz "Novembre"
szDec: .asciz "Décembre"
szLundi: .asciz "Lundi"
szMardi: .asciz "Mardi"
szMercredi: .asciz "Mercredi"
szJeudi: .asciz "Jeudi"
szVendredi: .asciz "Vendredi"
szSamedi: .asciz "Samedi"
szDimanche: .asciz "Dimanche"
szCarriageReturn: .asciz "\n"
.align 4
tbDayMonthYear: .int 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335
.int 366, 397, 425, 456, 486, 517, 547, 578, 609, 639, 670, 700
.int 731, 762, 790, 821, 851, 882, 912, 943, 974,1004,1035,1065
.int 1096,1127,1155,1186,1216,1247,1277,1308,1339,1369,1400,1430
tbMonthName: .int szJan
.int szFev
.int szMars
.int szAvril
.int szMai
.int szJuin
.int szJuil
.int szAout
.int szSept
.int szOct
.int szNov
.int szDec
tbDayName: .int szLundi
.int szMardi
.int szMercredi
.int szJeudi
.int szVendredi
.int szSamedi
.int szDimanche
 
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
.align 4
stTVal: .skip timeval_end
stTZone: .skip timezone_end
sZoneConv: .skip 100
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: @ entry of program
ldr r0,iAdrstTVal
ldr r1,iAdrstTZone
mov r7,#GETTIME
svc 0
cmp r0,#-1 @ error ?
beq 99f
ldr r1,iAdrstTVal
ldr r0,[r1,#timeval_sec] @ timestemp in second
bl dateFormatNum
ldr r0,[r1,#timeval_sec] @ timestemp in second
bl dateFormatAlpha
ldr r0,iTStest1
bl dateFormatNum
ldr r0,iTStest1
bl dateFormatAlpha
ldr r0,iTStest2
bl dateFormatNum
ldr r0,iTStest2
bl dateFormatAlpha
ldr r0,iTStest3
bl dateFormatNum
ldr r0,iTStest3
bl dateFormatAlpha
b 100f
99:
ldr r0,iAdrszMessError
bl affichageMess
100: @ standard end of the program
mov r0,#0 @ return code
mov r7,#EXIT @ request to exit program
svc 0 @ perform the system call
 
iAdrszMessError: .int szMessError
iAdrstTVal: .int stTVal
iAdrstTZone: .int stTZone
iAdrszCarriageReturn: .int szCarriageReturn
iAdrsZoneConv: .int sZoneConv
iTStest1: .int 1609508339 @ 01/01/2021
iTStest2: .int 1657805939 @ 14/07/2022
iTStest3: .int 1767221999 @ 31/12/2025
/******************************************************************/
/* date format numeric */
/******************************************************************/
/* r0 contains the timestamp in seconds */
dateFormatNum:
push {r1-r11,lr} @ save registers
ldr r2,iSecJan2020
sub r0,r0,r2 @ total secondes to 01/01/2020
mov r1,#60
bl division
mov r0,r2
mov r6,r3 @ compute secondes
mov r1,#60
bl division
mov r7,r3 @ compute minutes
mov r0,r2
mov r1,#24
bl division
mov r8,r3 @ compute hours
mov r0,r2
mov r11,r0
mov r1,#(365 * 4 + 1)
bl division
lsl r9,r2,#2 @ multiply by 4 = year1
mov r1,#(365 * 4 + 1)
mov r0,r11
bl division
mov r10,r3
 
ldr r1,iAdrtbDayMonthYear
mov r2,#3
mov r3,#12
1:
mul r11,r3,r2
ldr r4,[r1,r11,lsl #2] @ load days by year
cmp r10,r4
bge 2f
sub r2,r2,#1
cmp r2,#0
bne 1b
2: @ r2 = year2
mov r5,#11
mul r11,r3,r2
lsl r11,#2
add r11,r1 @ table address
3:
ldr r4,[r11,r5,lsl #2] @ load days by month
cmp r10,r4
bge 4f
subs r5,r5,#1
bne 3b
4: @ r5 = month - 1
mul r11,r3,r2
add r11,r5
ldr r1,iAdrtbDayMonthYear
ldr r3,[r1,r11,lsl #2]
sub r0,r10,r3
add r0,r0,#1 @ final compute day
ldr r1,iAdrsZoneConv
bl conversion10 @ this function do not zero final
mov r11,#0 @ store zero final
strb r11,[r1,r0]
ldr r0,iAdrszMessResult
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ insert result at first @ character
mov r3,r0
add r0,r5,#1 @ final compute month
cmp r0,#12
subgt r0,#12
ldr r1,iAdrsZoneConv
bl conversion10
mov r11,#0 @ store zero final
strb r11,[r1,r0]
mov r0,r3
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ insert result at next @ character
mov r3,r0
ldr r11,iYearStart
add r0,r9,r11
add r0,r0,r2 @ final compute year = 2020 + year1 + year2
ldr r1,iAdrsZoneConv
bl conversion10
mov r11,#0 @ store zero final
strb r11,[r1,r0]
mov r0,r3
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ insert result at next @ character
bl affichageMess
100:
pop {r1-r11,lr} @ restaur registers
bx lr @ return
iAdrszMessResult: .int szMessResult
/******************************************************************/
/* date format alphanumeric */
/******************************************************************/
/* r0 contains the timestamp in seconds */
dateFormatAlpha:
push {r1-r10,lr} @ save registers
ldr r2,iSecJan2020
sub r0,r0,r2 @ total secondes to 01/01/2020
mov r6,r0
mov r1,#60
bl division
mov r0,r2
mov r1,#60
bl division
mov r0,r2
mov r1,#24
bl division
mov r0,r2
mov r8,r0
mov r1,#(365 * 4 + 1)
bl division
lsl r9,r2,#2 @ multiply by 4 = year1
mov r1,#(365 * 4 + 1)
mov r0,r8
bl division
mov r10,r3 @ reste
 
ldr r1,iAdrtbDayMonthYear
mov r7,#3
mov r3,#12
1:
mul r8,r3,r7
ldr r4,[r1,r8,lsl #2] @ load days by year
cmp r10,r4
bge 2f
sub r7,r7,#1
cmp r7,#0
bne 1b
2: @ r7 = year2
mov r5,#11
mul r8,r3,r7
lsl r8,#2
add r8,r1
3:
ldr r4,[r8,r5,lsl #2] @ load days by month
cmp r10,r4
bge 4f
subs r5,r5,#1
bne 3b
4: @ r5 = month - 1
 
mov r0,r6 @ number secondes depuis 01/01/2020
ldr r1,iNbSecByDay
bl division
mov r0,r2
mov r1,#7
bl division
add r2,r3,#2
cmp r2,#7
subge r2,#7
ldr r1,iAdrtbDayName
ldr r1,[r1,r2,lsl #2]
ldr r0,iAdrszMessResult1
bl strInsertAtCharInc @ insert result at next @ character
mov r3,r0
mov r8,#12
mul r11,r8,r7
add r11,r5
ldr r1,iAdrtbDayMonthYear
ldr r8,[r1,r11,lsl #2]
sub r0,r10,r8
add r0,r0,#1 @ final compute day
ldr r1,iAdrsZoneConv
bl conversion10 @ this function do not zero final
mov r8,#0 @ store zero final
strb r8,[r1,r0]
mov r0,r3
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ insert result at first @ character
mov r3,r0
ldr r1,iAdrtbMonthName
cmp r5,#12
subge r5,#12
ldr r1,[r1,r5,lsl #2] @ month name
mov r0,r3
bl strInsertAtCharInc @ insert result at first @ character
mov r3,r0
ldr r0,iYearStart
add r0,r7
add r0,r9 @ final compute year = 2020 + year1 + year2
 
ldr r1,iAdrsZoneConv
bl conversion10 @ this function do not zero final
mov r8,#0 @ store zero final
strb r8,[r1,r0]
mov r0,r3
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ insert result at first @ character
bl affichageMess
100:
pop {r1-r10,lr} @ restaur registers
bx lr @ return
iAdrszMessResult1: .int szMessResult1
iSecJan2020: .int 1577836800
iAdrtbDayMonthYear: .int tbDayMonthYear
iYearStart: .int 2020
iAdrtbMonthName: .int tbMonthName
iAdrtbDayName: .int tbDayName
iNbSecByDay: .int 3600 * 24
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
{{Output}}
<pre>
Date : 30/3/2020
Date day : Lundi 30 Mars 2020
Date : 1/1/2021
Date day : Vendredi 1 Janvier 2021
Date : 14/7/2022
Date day : Jeudi 14 Juillet 2022
Date : 31/12/2025
Date day : Mercredi 31 Décembre 2025
</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">currentTime: now
 
print to :string.format: "YYYY-MM-dd" currentTime
print to :string.format: "dddd, MMMM dd, YYYY" currentTime</syntaxhighlight>
 
{{out}}
 
<pre>2021-03-11
Thursday, March 11, 2021</pre>
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight lang="autohotkey">FormatTime, Date1, , yyyy-MM-dd ; "2007-11-10"
FormatTime, Date2, , LongDate ; "Sunday, November 10, 2007"
MsgBox %Date1% `n %Date2%</langsyntaxhighlight>
 
=={{header|AutoIt}}==
This solution uses the locale settings for names of days and months.
<syntaxhighlight lang="autoit">
<lang AutoIt>
#include <Date.au3>
 
Line 182 ⟶ 1,207:
Return $ret[3]
EndFunc
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 192 ⟶ 1,217:
=={{header|AWK}}==
{{works with|Gawk}}
<langsyntaxhighlight lang="awk">$ awk 'BEGIN{t=systime();print strftime("%Y-%m-%d",t)"\n"strftime("%A, %B %d, %Y",t)}'
2009-05-15
Friday, May 15, 2009</langsyntaxhighlight>
 
=={{header|BaCon}}==
<langsyntaxhighlight lang="freebasic">' Date format
n = NOW
PRINT YEAR(n), MONTH(n), DAY(n) FORMAT "%ld-%02ld-%02ld\n"
PRINT WEEKDAY$(n), MONTH$(n), DAY(n), YEAR(n) FORMAT "%s, %s %02ld, %ld\n"</langsyntaxhighlight>
 
{{out}}
Line 209 ⟶ 1,234:
=={{header|BASIC}}==
{{works with|FreeBASIC}}
<langsyntaxhighlight lang="freebasic">#include "vbcompat.bi"
 
DIM today As Double = Now()
 
PRINT Format(today, "yyyy-mm-dd")
PRINT Format(today, "dddd, mmmm d, yyyy")</langsyntaxhighlight>
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">
@echo off
setlocal enabledelayedexpansion
Line 253 ⟶ 1,278:
echo %fulldayname%, %monthname% %day%, %year%
pause>nul
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 261 ⟶ 1,286:
 
=={{header|BBC BASIC}}==
<langsyntaxhighlight lang="bbcbasic"> daysow$ = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
months$ = "January February March April May June " + \
\ "July August September October November December"
Line 278 ⟶ 1,303:
DEF FNrtrim(A$)
WHILE RIGHT$(A$) = " " A$ = LEFT$(A$) : ENDWHILE
= A$</langsyntaxhighlight>
 
=={{header|Beads}}==
<pre>
// time_to_str(format, time, city, lang)
// format directives:
// [sun] - abbreviated weekday, e.g. Sun
// [sunday] - full weekday name, e.g. Sunday
// [jan] - abbrev month
// [january] - full month
// [day] - day of the month 1, 2, ..31
// [day2] - day of the month as two digits 01, 02, ..31
// [hour] - hour 00, 01, 03..23
// [hour12] - hour 1..12
// [julian] - day of the year 1..366
// [month] - month 1..12
// [month2] - month as two digits 01, 02, ..12
// [minute] - Minute 00, 01, 02..59
// [am] - AM or PM
// [sec] - second 00, 01, 02..61
// [msec] - millisecond 000...999
// [week sun] - week number of the year, sunday based (ranges 01-53, per ISO spec)
// [week mon] - week number of the year, monday based
// [year] - year with century 2024
// [year2] - year without century 00, 01, ..99
// [date] - default date format (e.g. Jan 14, 2015 )
// [date time] - (e.g. Jan 14, 2015 3:45 PM)
// [iso date] = [year]-[month2]-[day2], e.g. 2015-02-22
// [iso time] = [hour]:[minute]:[second], e.g. 18:06:05
</pre>
<syntaxhighlight lang="beads">beads 1 program 'Date format'
 
calc main_init
log time_to_str('[iso date]')
log time_to_str('[sunday], [january] [day2], [year]')</syntaxhighlight>
 
{{out}}
<pre>
2021-03-11
Thursday, March 11, 2021
</pre>
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdlib.h>
#include <stdio.h>
#include <time.h>
Line 303 ⟶ 1,368:
(void) printf("%s\n", buf);
return EXIT_SUCCESS;
}</langsyntaxhighlight>
{{out}}
<pre>
Line 309 ⟶ 1,374:
Wednesday, May 13, 2009
Wednesday, May 13, 2009</pre>
 
=={{header|C sharp|C#}}==
<syntaxhighlight lang="csharp">using System;
 
namespace RosettaCode.DateFormat
{
class Program
{
static void Main(string[] args)
{
DateTime today = DateTime.Now.Date;
Console.WriteLine(today.ToString("yyyy-MM-dd"));
Console.WriteLine(today.ToString("dddd, MMMMM d, yyyy"));
}
}
}</syntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">// Display the current date in the formats of "2007-11-10"
// and "Sunday, November 10, 2007".
 
Line 374 ⟶ 1,455:
std::cout << d.getTextDate() << std::endl;
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>
Line 380 ⟶ 1,461:
Thursday, May 14, 2009
</pre>
 
=={{header|C sharp|C#}}==
<lang csharp>using System;
 
namespace RosettaCode.DateFormat
{
class Program
{
static void Main(string[] args)
{
DateTime today = DateTime.Now.Date;
Console.WriteLine(today.ToString("yyyy-MM-dd"));
Console.WriteLine(today.ToString("dddd, MMMMM d, yyyy"));
}
}
}</lang>
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="lisp">(let [now (.getTime (java.util.Calendar/getInstance))
f1 (java.text.SimpleDateFormat. "yyyy-MM-dd")
f2 (java.text.SimpleDateFormat. "EEEE, MMMM dd, yyyy")]
(println (.format f1 now))
(println (.format f2 now)))</langsyntaxhighlight>
 
{{out}}
Line 410 ⟶ 1,475:
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Date-Format.
 
Line 473 ⟶ 1,538:
 
GOBACK
.</langsyntaxhighlight>
 
=={{header|CoffeeScript}}==
=== ECMAScript ≥ 5.1 ===
Is supported by at least: Chrome 24, Firefox/Gecko 29, IE 11, Opera 15, and Node.js (at least as of 2015).
<langsyntaxhighlight lang="coffeescript">
date = new Date
 
Line 492 ⟶ 1,557:
day: 'numeric'
year: 'numeric'
</syntaxhighlight>
</lang>
 
=== Portable version ===
<langsyntaxhighlight lang="coffeescript">
# JS does not have extensive formatting support out of the box. This code shows
# how you could create a date formatter object.
Line 522 ⟶ 1,587:
console.log formatter.brief(date)
console.log formatter.verbose(date)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 531 ⟶ 1,596:
 
=={{header|ColdFusion}}==
<langsyntaxhighlight lang="cfm"><cfoutput>
#dateFormat(Now(), "YYYY-MM-DD")#<br />
#dateFormat(Now(), "DDDD, MMMM DD, YYYY")#
</cfoutput></langsyntaxhighlight>
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(defconstant *day-names*
#("Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"))
(defconstant *month-names*
Line 546 ⟶ 1,611:
(format t "~4d-~2,'0d-~2,'0d~%" year month date)
(format t "~a, ~a ~d, ~4d~%"
(aref *day-names* day) (aref *month-names* month) date year))</langsyntaxhighlight>
 
With the local-time library:
 
<syntaxhighlight lang="lisp">
(local-time:format-timestring nil (local-time:now) :format '(:year "-" (:month 2) "-" (:day 2)))
;; => "2019-11-13"
(local-time:format-timestring nil (local-time:now) :format '(:long-weekday ", " :long-month #\space (:day 2) ", " :year))
;; => "Wednesday, November 13, 2019"
</syntaxhighlight>
 
=={{header|Component Pascal}}==
BlackBox Component Builder
<syntaxhighlight lang="oberon2">
<lang obero2>
MODULE DateFormat;
IMPORT StdLog, Dates;
Line 572 ⟶ 1,646:
END Do;
END DateFormat.
</syntaxhighlight>
</lang>
Execute: ^Q DateFormat.Do<br/>
{{out}}
Line 583 ⟶ 1,657:
:> 01 de septiembre de 2013
</pre>
 
=={{header|Crystal}}==
{{works with|Crystal|0.33}}
<syntaxhighlight lang="crystal">require "time"
 
time = Time.local
puts time.to_s("%Y-%m-%d")
puts time.to_s("%A, %B %d, %Y")
</syntaxhighlight>
 
=={{header|D}}==
{{works with|D|DMD 1.026}}
{{libheader|Tango}}
<langsyntaxhighlight lang="d">module datetimedemo ;
 
import tango.time.Time ;
Line 603 ⟶ 1,686:
d = g.toTime(2008, 2, 1, 0, 0, 0, 0, g.AD_ERA) ;
Stdout.format("{:dddd, MMMM d, yyy}", d).newline ;
}</langsyntaxhighlight>
{{out}}
<pre>2007-11-10
Line 610 ⟶ 1,693:
 
=={{header|Delphi}}==
<langsyntaxhighlight Delphilang="delphi">ShowMessage(FormatDateTime('yyyy-mm-dd', Now) +#13#10+ FormatDateTime('dddd, mmmm dd, yyyy', Now));</langsyntaxhighlight>
{{out}}
<pre>
2022-02-16
Wednesday, February 16, 2022
Redirecting to
</pre>
 
=={{header|Diego}}==
<syntaxhighlight lang="diego">me_lang(en)_cal(gregorian);
me_msg()_now()_format(yyyy-mm-dd);
me_msg()_now()_format(eeee, mmmm dd, yyyy);</syntaxhighlight>
 
=={{header|EGL}}==
<syntaxhighlight lang="egl">
// 2012-09-26
SysLib.writeStdout(StrLib.formatDate(DateTimeLib.currentDate(), "yyyy-MM-dd"));
// Wednesday, September 26, 2012
SysLib.setLocale("en", "US");
SysLib.writeStdout(StrLib.formatDate(DateTimeLib.currentDate(), "EEEE, MMMM dd, yyyy"));
</syntaxhighlight>
{{out}}
<pre>
2012-09-26
Wednesday, September 26, 2012
</pre>
 
=={{header|Elixir}}==
{{trans|Erlang}}
{{works with|Elixir|1.4}}
<langsyntaxhighlight lang="elixir">defmodule Date_format do
def iso_date, do: Date.utc_today |> Date.to_iso8601
Line 637 ⟶ 1,745:
IO.puts Date_format.long_date
IO.puts Date_format.iso_date(2007,11,10)
IO.puts Date_format.long_date(2007,11,10)</langsyntaxhighlight>
 
{{out}}
Line 648 ⟶ 1,756:
 
=={{header|Emacs Lisp}}==
<langsyntaxhighlight Lisplang="lisp">(format-time-string "%Y-%m-%d")
(format-time-string "%F") ;; new in Emacs 24
;; => "2015-11-08"
 
(format-time-string "%A, %B %e, %Y")
;; => "Sunday, November 8, 2015"</syntaxhighlight>
</lang>
 
<code>%e</code> is blank-padded day number, or <code>%d</code> for zero-padded. Month and weekday names follow the current locale. On a POSIX style system this is the usual <code>LC_TIME</code> or <code>LC_ALL</code> environment variables. GNU Emacs variable <code>system-time-locale</code> can override this if desired.
Line 660 ⟶ 1,767:
=={{header|Erlang}}==
 
<langsyntaxhighlight Erlanglang="erlang">-module(format_date).
-export([iso_date/0, iso_date/1, iso_date/3, long_date/0, long_date/1, long_date/3]).
-import(calendar,[day_of_the_week/1]).
Line 683 ⟶ 1,790:
MonthName = element(Month, Months),
append([WeekdayName, ", ", MonthName, " ", integer_to_list(Day), ", ",
integer_to_list(Year)]).</langsyntaxhighlight>
 
=={{header|Euphoria}}==
<langsyntaxhighlight Euphorialang="euphoria">constant days = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
constant months = {"January","February","March","April","May","June",
"July","August","September","October","November","December"}
Line 696 ⟶ 1,803:
 
printf(1,"%d-%02d-%02d\n",now[1..3])
printf(1,"%s, %s %d, %d\n",{days[now[7]],months[now[2]],now[3],now[1]})</langsyntaxhighlight>
 
=={{header|EGL}}==
<lang EGL>
// 2012-09-26
SysLib.writeStdout(StrLib.formatDate(DateTimeLib.currentDate(), "yyyy-MM-dd"));
// Wednesday, September 26, 2012
SysLib.setLocale("en", "US");
SysLib.writeStdout(StrLib.formatDate(DateTimeLib.currentDate(), "EEEE, MMMM dd, yyyy"));
</lang>
{{out}}
<pre>
2012-09-26
Wednesday, September 26, 2012
</pre>
 
=={{header|F_Sharp|F#}}==
"F# Interactive" session:
<langsyntaxhighlight lang="fsharp">> open System;;
> Console.WriteLine( DateTime.Now.ToString("yyyy-MM-dd") );;
2010-08-13
> Console.WriteLine( "{0:D}", DateTime.Now );;
Friday, August 13, 2010</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: formatting calendar io ;
 
now "%Y-%m-%d" strftime print
now "%A, %B %d, %Y" strftime print</langsyntaxhighlight>
 
=={{header|Fantom}}==
Line 730 ⟶ 1,823:
Today's date can be retrieved using 'Date.today'. The 'toLocale' method can be passed formatting information to determine how the date should be represented as a string. The rules are described at http://fantom.org/doc/sys/Date.html#toLocale
 
<langsyntaxhighlight lang="fantom">
fansh> Date.today.toLocale("YYYY-MM-DD")
2011-02-24
fansh> Date.today.toLocale("WWWW, MMMM DD, YYYY")
Thursday, February 24, 2011
</syntaxhighlight>
</lang>
 
=={{header|Forth}}==
<langsyntaxhighlight lang="forth">: .-0 ( n -- n )
[char] - emit
dup 10 < if [char] 0 emit then ;
Line 792 ⟶ 1,885:
3dup weekday weekdays type ." , "
>R 1- months type space 1 u.r ." , " R> .
drop drop drop ;</langsyntaxhighlight>
 
==={ Version 2}: Meta Language ===
Forth is less of a language and more of an extensible toolkit of simple routines. This version attempts to demonstrate using the simple routines to extend Forth. Then using the language extensions and the power of concatenative language to solve the problem. This solution could create numerous date formats as one line definitions now that we have our "date" words defined. Typically these extensions would be saved as a library file.
 
<syntaxhighlight lang="forth">\ Build up a "language" for date formatting
This version attempts to demonstrate creating language extensions to make use of the power of concatenative language. Then using the language extensions to solve the problem easily.
 
<LANG>\ utility words
: UNDER+ ( a b c -- a+c b ) ROT + SWAP ;
: 3DUP ( a b c -- a b c a b c ) 2 PICK 2 PICK 2 PICK ;
Line 832 ⟶ 1,926:
: NTH$ ( n list -- $addr ) SWAP 0 DO NEXT$ LOOP ; \ get nth string
 
: " ( -- ) [CHAR] " WORD C@ 1CHAR+ ALLOT ; \ compile text toupto "
 
\ make the lists
Line 846 ⟶ 1,940:
: ]MONTH$. ( n -- ) MONTHS NTH$ WRITE$ ;
: ]DAY$. ( n -- ) DAYS NTH$ WRITE$ ;
\ ===========================================
 
 
\ Task Code begins
\ ===========================================
\ Rosetta Task Code Begins
 
\ Rosetta Date Format 1
Line 855 ⟶ 1,950:
\ Rosetta Date Format 2
: LONG.DATE ( d m y -- )
3DUP CDAY DOW ]DAY$. ',' -ROT ]MONTH$. SPACE ##. ',' ####. ;</LANGsyntaxhighlight>
 
 
 
Test at the Forth Console
<syntaxhighlight lang="forth"> 5 7 2018 Y-M-D. 2018-07-05 ok
ok
5 7 2018 LONG.DATE Thursday, July 05, 2018 ok
</syntaxhighlight>
 
=={{header|Fortran}}==
{{works with|Fortran|95 and later}}
The subroutine DATE_AND_TIME does not return day of week information so we have to write our own function for that
<langsyntaxhighlight lang="fortran">PROGRAM DATE
 
IMPLICIT NONE
Line 928 ⟶ 2,031:
END FUNCTION Day_of_week
 
END PROGRAM DATE</langsyntaxhighlight>
{{out}}
2008-12-14
Line 934 ⟶ 2,037:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
#Include "vbcompat.bi"
Line 943 ⟶ 2,046:
Print
Print "Press any key to quit the program"
Sleep</langsyntaxhighlight>
 
{{out}}
Line 949 ⟶ 2,052:
This example was created on : 2016-10-02
In other words on : Sunday, October 2, 2016
</pre>
 
=={{header|Free Pascal}}==
<syntaxhighlight lang="pascal">program Format_Date_Time;
uses
SysUtils;
begin
WriteLn(FormatDateTime('yyyy-mm-dd', Now) +#13#10+ FormatDateTime('dddd, mmmm dd, yyyy', Now));
end.
</syntaxhighlight>
{{out}}
<pre>
2022-02-16
Wednesday, February 16, 2022
</pre>
 
=={{header|Frink}}==
<langsyntaxhighlight lang="frink">
println[now[] -> ### yyyy-MM-dd ###]
println[now[] -> ### EEEE, MMMM d, yyyy ###]
</syntaxhighlight>
</lang>
 
=={{header|FunL}}==
<langsyntaxhighlight lang="funl">println( format('%tF', $date) )
println( format('%1$tA, %1$tB %1$td, %1$tY', $date) )</langsyntaxhighlight>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">window 1
 
print date(@"yyyy-MM-dd")
print date(@"EEEE, MMMM dd, yyyy")
 
HandleEvents</syntaxhighlight>
 
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/ You can run this code. Copy the code, click this link, paste it in and press 'Run !']'''
<langsyntaxhighlight lang="gambas">Public Sub Main()
 
Print Format(Now, "yyyy - mm - dd")
Print Format(Now, "dddd, mmmm dd, yyyy")
 
End</langsyntaxhighlight>
Output:
<pre>
Line 977 ⟶ 2,102:
=={{header|Go}}==
In an interesting design, you specify your format by providing the format for the date and time 01/02 03:04:05PM '06 -0700
<langsyntaxhighlight lang="go">package main
 
import "time"
Line 985 ⟶ 2,110:
fmt.Println(time.Now().Format("2006-01-02"))
fmt.Println(time.Now().Format("Monday, January 2, 2006"))
}</langsyntaxhighlight>
{{out}}
<pre>
Line 994 ⟶ 2,119:
=={{header|Groovy}}==
Solution:
<langsyntaxhighlight lang="groovy">def isoFormat = { date -> date.format("yyyy-MM-dd") }
def longFormat = { date -> date.format("EEEE, MMMM dd, yyyy") }</langsyntaxhighlight>
 
Test Program:
<langsyntaxhighlight lang="groovy">def now = new Date()
println isoFormat(now)
println longFormat(now)</langsyntaxhighlight>
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.Time
(FormatTime, formatTime, defaultTimeLocale, utcToLocalTime,
getCurrentTimeZone, getCurrentTime)
Line 1,013 ⟶ 2,138:
main = do
t <- pure utcToLocalTime <*> getCurrentTimeZone <*> getCurrentTime
putStrLn $ unlines (formats <*> pure t)</langsyntaxhighlight>
'''Sample output:'''
<pre>2017-06-05
Line 1,019 ⟶ 2,144:
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest"> CHARACTER string*40
 
WRITE(Text=string, Format='UCCYY-MM-DD') 0 ! string: 2010-03-13
Line 1,031 ⟶ 2,156:
EDIT(Text=string, Right=' ', Mark1, Right=';', Right=3, Mark2, Delete, Insert=', '//cMonth, Right=';', RePLaceby=',')
 
END</langsyntaxhighlight>
 
== {{header|Icon}} and {{header|Unicon}} ==
<langsyntaxhighlight Iconlang="icon">procedure main()
write(map(&date,"/","-"))
write(&dateline ? tab(find(&date[1:5])+4))
end</langsyntaxhighlight>
 
{{out}}
Line 1,045 ⟶ 2,170:
=={{header|J}}==
Short format using built in formatting:
<langsyntaxhighlight lang="j"> 6!:0 'YYYY-MM-DD'
2010-08-19</langsyntaxhighlight>
 
Verb to show custom format:
<langsyntaxhighlight lang="j">require 'dates system/packages/misc/datefmt.ijs'
days=:;:'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'
fmtDate=: [:((days ;@{~ weekday),', ',ms0) 3 {.]
 
fmtDate 6!:0 ''
Thursday, August 19, 2010</langsyntaxhighlight>
 
=={{header|Java}}==
<syntaxhighlight lang="java">
<lang java>import java.util.Calendar;
public static void main(String[] args) {
long millis = System.currentTimeMillis();
System.out.printf("%tF%n", millis);
System.out.printf("%tA, %1$tB %1$td, %1$tY%n", millis);
}
</syntaxhighlight>
<pre>
2023-05-10
Wednesday, May 10, 2023
</pre>
<br />
An alternate demonstration
<syntaxhighlight lang="java">
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.text.DateFormatSymbols;
import java.util.Date;
import java.text.DateFormat;
public class Dates{
import java.text.SimpleDateFormat;
public static void main(String[] args){
public class Dates
{
public static void main(final String[] args)
{
Calendar now = new GregorianCalendar(); //months are 0 indexed, dates are 1 indexed
DateFormatSymbols symbols = new DateFormatSymbols(); //names for our months and weekdays
Line 1,077 ⟶ 2,212:
System.out.print(symbols.getMonths()[now.get(Calendar.MONTH)] + " ");
System.out.println(now.get(Calendar.DATE) + ", " + now.get(Calendar.YEAR));
 
//using DateFormat
Date date = new Date();
DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(format1.format(date));
DateFormat format2 = new SimpleDateFormat("EEEE, MMMM dd, yyyy");
System.out.println(format2.format(date));
}
}
}</lang>
</syntaxhighlight>
Better use a library, see http://sourceforge.net/apps/mediawiki/threeten/index.php?title=ThreeTen
Better: use a library, see http://sourceforge.net/apps/mediawiki/threeten/index.php?title=ThreeTen
 
===Java 8 Date Time API===
<langsyntaxhighlight lang="java">
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
Line 1,103 ⟶ 2,232:
}
}
</syntaxhighlight>
</lang>
 
===Java Util Date API===
<syntaxhighlight lang="java">
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class DateFormat {
public static void main(String[]args){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat formatLong = new SimpleDateFormat("EEEE, MMMM dd, yyyy");
System.out.println(format.format(new Date()));
System.out.println(formatLong.format(new Date()));
}
}
</syntaxhighlight>
 
=={{header|JavaScript}}==
JavaScript does not have any built-in <code>strftime</code>-type functionality.
<langsyntaxhighlight lang="javascript">var now = new Date(),
weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
Line 1,113 ⟶ 2,257:
fmt2 = weekdays[now.getDay()] + ', ' + months[now.getMonth()] + ' ' + now.getDate() + ', ' + now.getFullYear();
console.log(fmt1);
console.log(fmt2);</langsyntaxhighlight>
<pre>2010-1-12
Tuesday, January 12, 2010</pre>
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">
<lang Joy>
DEFINE weekdays == [ "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday" ];
months == [ "January" "February" "March" "April" "May" "June" "July" "August"
"September" "October" "November" "December" ].
 
time localtime [ [0 at 'd 4 4 format] ["-"] [1 at 'd 2 2 format] ["-"] [2 at 'd 2 2 format] ]
[i] map [putchars] step '\n putch pop.
 
time localtime [ [8 at pred weekdays of] [", "] [1 at pred months of] [" "] [2 at 'd 1 1 format]
[", "] [0 at 'd 4 4 format] ] [i] map [putchars] step '\n putch pop.
</syntaxhighlight>
</lang>
 
=={{header|jq}}==
{{works with|jq|with strftime}}
<langsyntaxhighlight lang="sh">$ jq -n 'now | (strftime("%Y-%m-%d"), strftime("%A, %B %d, %Y"))'
"2015-07-02"
"Thursday, July 02, 2015"</langsyntaxhighlight>
 
WARNING: prior to July 2, 2015, there was a bug in jq affecting the display of the "day of week" (wday) and the "day of the year" (yday).
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
 
<langsyntaxhighlight lang="julia">ts = Dates.today()
 
println("Today's date is:")
println("\t$ts")
println("\t", Dates.format(ts, "E, U dd, yyyy"))</langsyntaxhighlight>
 
{{out}}
Line 1,152 ⟶ 2,297:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.0.6
 
import java.util.GregorianCalendar
Line 1,160 ⟶ 2,305:
println("%tF".format(now))
println("%tA, %1\$tB %1\$te, %1\$tY".format(now))
}</langsyntaxhighlight>
 
{{out}}
Line 1,167 ⟶ 2,312:
Monday, January 16, 2017
</pre>
 
=={{header|langur}}==
<syntaxhighlight lang="langur">var .now = dt//
var .format1 = "2006-01-02"
var .format2 = "Monday, January 2, 2006"
writeln $"\.now:dt format1;"
writeln $"\.now:dt format2;"</syntaxhighlight>
 
<syntaxhighlight lang="langur">var .now = dt//
writeln $"\.now:dt(2006-01-02);"
writeln $"\.now:dt(Monday, January 2, 2006);"</syntaxhighlight>
 
<syntaxhighlight lang="langur">writeln string dt//, "2006-01-02"
writeln string dt//, "Monday, January 2, 2006"</syntaxhighlight>
 
{{out}}
<pre>2020-03-26
Thursday, March 26, 2020</pre>
 
Langur is using the Go time package, and using its formatting method for output. It expects the following parts in a format string.
 
<pre>year: 2006 or 06
month: 01 or 1
month name: Jan or January
month day: 02 or _2 or 2
weekday name: Mon or Monday
hour: 03 or 3 or 15
minute: 04 or 4
second: 05 or 5
AM/PM: PM or pm
time zone offset: -07:00 or -0700 or -07
time zone name: MST</pre>
 
=={{header|Lasso}}==
<syntaxhighlight lang="lasso">
<lang Lasso>
date('11/10/2007')->format('%Q') // 2007-11-10
date('11/10/2007')->format('EEEE, MMMM d, YYYY') //Saturday, November 10, 2007
 
</syntaxhighlight>
</lang>
 
=={{header|Liberty BASIC}}==
<langsyntaxhighlight lang="lb">'Display the current date in the formats of "2007-11-10"
d$=date$("yyyy/mm/dd")
print word$(d$,1,"/")+"-"+word$(d$,2,"/")+"-"+word$(d$,3,"/")
Line 1,198 ⟶ 2,375:
monthLong$="January February March April May June July August September October November December"
 
print word$(weekDay$,theDay+1);", ";word$(monthLong$,month);" ";day;", ";year</langsyntaxhighlight>
 
 
=={{header|LiveCode}}==
<syntaxhighlight lang="livecode">on mouseUp pButtonNumber
put the date into tDate
convert tDate to dateItems
put item 1 of tDate & "-" & item 2 of tDate & "-" & item 3 of tDate & return into tMyFormattedDate
put tMyFormattedDate & the long date
end mouseUp </syntaxhighlight>
 
=={{header|Logo}}==
{{works with|UCB Logo}}
A bit of a cheat since Logo has no standard built-in time and date functions, but UCB Logo can call out to the shell, so:
<syntaxhighlight lang="logo">
print first shell [date +%F]
print first shell [date +"%A, %B %d, %Y"]
</syntaxhighlight>
{{Out}}
<pre>2020-09-16
Wednesday, September 16, 2020</pre>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">print( os.date( "%Y-%m-%d" ) )
print( os.date( "%A, %B %d, %Y" ) )</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
Print str$(today, "yyyy-mm-dd")
Print str$(today, "dddd, mmm, dd, yyyy")
</syntaxhighlight>
 
=={{header|Maple}}==
 
<syntaxhighlight lang="maple">
<lang Maple>
with(StringTools);
FormatTime("%Y-%m-%d")
FormatTime("%A,%B %d, %y")
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
 
<syntaxhighlight lang="mathematica">DateString[{"Year", "-", "Month", "-", "Day"}]
=={{header|Mathematica}}==
<lang Mathematica>DateString[{"YearDayName", "-, ", "MonthMonthName", "- ", "Day", ", ", "Year"}]</syntaxhighlight>
DateString[{"DayName", ", ", "MonthName", " ", "Day", ", ", "Year"}]</lang>
 
=={{header|MATLAB}} / {{header|Octave}}==
<langsyntaxhighlight MATLABlang="matlab">>> datestr(now,'yyyy-mm-dd')
 
ans =
Line 1,227 ⟶ 2,430:
ans =
 
Friday, June 18, 2010</langsyntaxhighlight>
 
=={{header|min}}==
{{works with|min|0.19.3}}
<syntaxhighlight lang="min">("YYYY-MM-dd" "dddd, MMMM dd, YYYY") ('timestamp dip tformat puts!) foreach</syntaxhighlight>
{{out}}
<pre>
2019-04-02
Tuesday, April 02, 2019
</pre>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">import "dateTime"
 
print dateTime.now("yyyy-MM-dd")
print dateTime.now("dddd, MMMM d, yyyy")</syntaxhighlight>
 
{{out}}
<pre>2023-12-28
Thursday, December 28, 2023
</pre>
 
=={{header|mIRC Scripting Language}}==
<langsyntaxhighlight lang="mirc">echo -ag $time(yyyy-mm-dd)
echo -ag $time(dddd $+ $chr(44) mmmm dd $+ $chr(44) yyyy)</langsyntaxhighlight>
 
=={{header|MUMPS}}==
{{works with|MUMPS|Intersystems' Caché|(all versions)}}
Functions starting with 'Z' or '$Z' are implementation specific.
<langsyntaxhighlight MUMPSlang="mumps">DTZ
WRITE !,"Date format 3: ",$ZDATE($H,3)
WRITE !,"Or ",$ZDATE($H,12),", ",$ZDATE($H,9)
QUIT</langsyntaxhighlight>
<p>MUMPS contains the integer number of days since December 31, 1840 in the first part of the system variable $HOROLOG.</p>
{{works with|MUMPS|all}}
<langsyntaxhighlight MUMPSlang="mumps">DTM(H)
;You can pass an integer, but the default is to use today's value
SET:$DATA(H)=0 H=$HOROLOG
Line 1,262 ⟶ 2,485:
WRITE !,$P(DN,",",DOW),", ",$P(MN,",",MO)," ",DA,", ",YR
KILL Y,YR,RD,MC,MO,DA,MN,DN,DOW
QUIT</langsyntaxhighlight>
Demos:<pre>
USER>D DTM^ROSETTA
Line 1,277 ⟶ 2,500:
Or Thursday, June 24, 2010
</pre>
 
=={{header|Nanoquery}}==
<syntaxhighlight lang="nanoquery">import Nanoquery.Util
 
d = new(Date)
println d.getYear() + "-" + d.getMonth() + "-" + d.getDay()
println d.getDayOfWeek() + ", " + d.getMonthName() + " " + d.getDay() + ", " + d.getYear()</syntaxhighlight>
 
=={{header|Neko}}==
<syntaxhighlight lang="actionscript">/**
<doc>
<h2>Date format</h2>
<p>Neko uses Int32 to store system date/time values.
And lib C strftime style formatting for converting to string form</p>
</doc>
*/
 
var date_now = $loader.loadprim("std@date_now", 0)
var date_format = $loader.loadprim("std@date_format", 2)
 
var now = date_now()
$print(date_format(now, "%F"), "\n")
$print(date_format(now, "%A, %B %d, %Y"), "\n")</syntaxhighlight>
{{out}}
<pre>prompt$ nekoc date-format.neko
prompt$ neko date-format.n
2018-11-13
Tuesday, November 13, 2018</pre>
 
=={{header|NetRexx}}==
<syntaxhighlight lang="netrexx">
<lang NetRexx>
import java.text.SimpleDateFormat
say SimpleDateFormat("yyyy-MM-dd").format(Date())
say SimpleDateFormat("EEEE, MMMM dd, yyyy").format(Date())
</syntaxhighlight>
</lang>
{{out}}
<pre>2019-02-10
Sonntag, Februar 10, 2019</pre>
 
=={{header|NewLISP}}==
<langsyntaxhighlight NewLISPlang="newlisp">; file: date-format.lsp
; url: http://rosettacode.org/wiki/Date_format
; author: oofoe 2012-02-01
Line 1,319 ⟶ 2,573:
(println "long: " (date (date-value) 0 "%A, %B %#d, %Y"))
 
(exit)</langsyntaxhighlight>
 
{{out}}
Line 1,329 ⟶ 2,583:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import times
 
var t = getTime().getLocalTimenow()
echo(t.format("yyyy-MM-dd"))
echo(t.format("dddd',' MMMM d',' yyyy"))</langsyntaxhighlight>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">
use IO;
use Time;
Line 1,352 ⟶ 2,606:
}
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,361 ⟶ 2,615:
 
=={{header|Objective-C}}==
<langsyntaxhighlight lang="objc">NSLog(@"%@", [NSDate date]);
NSLog(@"%@", [[NSDate date] descriptionWithCalendarFormat:@"%Y-%m-%d" timeZone:nil locale:nil]);
NSLog(@"%@", [[NSDate date] descriptionWithCalendarFormat:@"%A, %B %d, %Y" timeZone:nil locale:nil]);</langsyntaxhighlight>
 
{{works with|Mac OS X|10.4+}}
{{works with|iOS}}
<langsyntaxhighlight lang="objc">NSLog(@"%@", [NSDate date]);
NSDateFormatter *dateFormatter = [[NSDateFormat alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);
[dateFormatter setDateFormat:@"EEEE, MMMM d, yyyy"];
NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);</langsyntaxhighlight>
 
=={{header|OCaml}}==
 
<langsyntaxhighlight lang="ocaml"># #load "unix.cma";;
# open Unix;;
 
Line 1,388 ⟶ 2,642:
 
# Printf.sprintf "%d-%02d-%02d" (1900 + gmt.tm_year) (1 + gmt.tm_mon) gmt.tm_mday ;;
- : string = "2008-08-29"</langsyntaxhighlight>
 
<langsyntaxhighlight lang="ocaml">let months = [| "January"; "February"; "March"; "April"; "May"; "June";
"July"; "August"; "September"; "October"; "November"; "December" |]
 
Line 1,401 ⟶ 2,655:
gmt.tm_mday
(1900 + gmt.tm_year) ;;
- : string = "Friday, August 29, 2008"</langsyntaxhighlight>
 
=={{header|ooRexx}}==
<syntaxhighlight lang="oorexx">/* REXX */
dats='20071123'
Say date('I',dats,'S')
Say date('W',dats,'S')',' date('M',dats,'S') substr(dats,7,2)',' left(dats,4)
Say date('W',dats,'S')',' date('M',dats,'S') translate('gh, abcd',dats,'abcdefgh')
dati=date('I')
Say dati
Say date('W',dati,'I')',' date('M',dati,'I') translate('ij, abcd',dati,'abcdefghij')</syntaxhighlight>
{{out}}2007-11-23
Friday, November 23, 2007
Friday, November 23, 2007
2020-06-05
Friday, June 05, 2020
 
=={{header|OxygenBasic}}==
<langsyntaxhighlight lang="oxygenbasic">
extern lib "kernel32.dll"
 
Line 1,436 ⟶ 2,705:
print "" t.wYear "-" month "-" day
print WeekDay[t.wDayOfWeek+1 and 7 ] " " MonthName[t.wMonth and 31] " " t.wDay " " t.wYear
</syntaxhighlight>
</lang>
 
=={{header|Oz}}==
Getting the current local date is easy, but we have to do the formatting manually.
<langsyntaxhighlight lang="oz">declare
WeekDays = unit(0:"Sunday" "Monday" "Tuesday" "Wednesday"
"Thursday" "Friday" "Saturday")
Line 1,465 ⟶ 2,734:
in
{System.showInfo {DateISO {OS.localTime}}}
{System.showInfo {DateLong {OS.localTime}}}</langsyntaxhighlight>
 
=={{header|Pascal}}==
{{works with|Turbo Pascal|5.5}}
<langsyntaxhighlight Pascallang="pascal">program dateform;
uses DOS;
 
Line 1,523 ⟶ 2,792:
mname := m2s(mo); dname := d2s(dow);
writeln(dname,', ',mname,' ',dy,', ',yr)
end.</langsyntaxhighlight>
 
{{out}}
Line 1,531 ⟶ 2,800:
=={{header|Perl}}==
{{libheader|POSIX}}
<langsyntaxhighlight lang="perl">use POSIX;
 
print strftime('%Y-%m-%d', 0, 0, 0, 10, 10, 107), "\n";
print strftime('%A, %B %d, %Y', 0, 0, 0, 10, 10, 107), "\n";</langsyntaxhighlight>
 
{{out}} with locales '''C''':
Line 1,545 ⟶ 2,814:
 
Actual date:
<langsyntaxhighlight lang="perl">use POSIX;
 
print strftime('%Y-%m-%d', localtime), "\n";
print strftime('%A, %B %d, %Y', localtime), "\n";</langsyntaxhighlight>
 
{{out}} with locales '''C''':
2008-02-13
Wednesday, February 13, 2008
 
 
=={{header|Perl 6}}==
{{libheader|DateTime::Format}}
<lang perl6>use DateTime::Format;
 
my $dt = DateTime.now;
 
say strftime('%Y-%m-%d', $dt);
say strftime('%A, %B %d, %Y', $dt);</lang>
 
Rudimentary DateTime operations are built-in,
as the DateTime class itself is built into a Perl 6 compiler:
<lang perl6>use DateTime::Format;
 
my $dt = DateTime.now;
 
say $dt.yyyy-mm-dd;
say strftime('%A, %B %d, %Y', $dt);</lang>
 
=={{header|Phix}}==
{{libheader|Phix/basics}}
<lang Phix>include builtins\timedate.e
<!--<syntaxhighlight lang="phix">(phixonline)-->
?format_timedate(date(),"YYYY-MM-DD")
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
?format_timedate(date(),"Dddd, Mmmm d, YYYY")</lang>
<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>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">date</span><span style="color: #0000FF;">(),</span><span style="color: #008000;">"YYYY-MM-DD"</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">date</span><span style="color: #0000FF;">(),</span><span style="color: #008000;">"Dddd, Mmmm d, YYYY"</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 1,585 ⟶ 2,839:
=={{header|PHP}}==
Formatting rules: http://www.php.net/date
<langsyntaxhighlight lang="php"><?php
echo date('Y-m-d', time())."\n";
echo date('l, F j, Y', time())."\n";
?></langsyntaxhighlight>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(let (Date (date) Lst (date Date))
(prinl (dat$ Date "-")) # 2010-02-19
(prinl # Friday, February 19, 2010
Line 1,600 ⟶ 2,854:
(caddr Lst)
", "
(car Lst) ) )</langsyntaxhighlight>
 
=={{header|Pike}}==
<syntaxhighlight lang="pike">
<lang Pike>> write("%d-%02d-%02d\n", day->year_no(), day->month_no(), day->month_day());
object cal = Calendar.ISO.Day();
2011-11-05
write( cal->format_ymd() +"\n" );
 
string special = sprintf("%s, %s %d, %d",
> write("%s, %s %s, %s\n", day->week_day_name(), day->month_name(), day->month_day_name(), day->year_name());
cal->week_day_name(),
Saturday, November 5, 2011
cal->month_name(),
 
cal->month_day(),
> write(day->format_ymd()+"\n");
cal->year_no());
2011-11-05
write( special +"\n" );
 
</syntaxhighlight>
> write(day->format_ext_ymd()+"\n");
{{Out}}
Saturday, 5 November 2011</lang>
<pre>
2020-01-03
Friday, January 3, 2020
</pre>
 
=={{header|PL/I}}==
===Version 1===
<langsyntaxhighlight lang="pli">df: proc Options(main);
declare day_of_week(7) character (9) varying initial(
'Sunday','Monday','Tuesday','Wednesday',
Line 1,631 ⟶ 2,889:
put edit(substr(today,1,3),' ',substr(today,4,2),', ',
substr(today,6,4))(A);
end;</langsyntaxhighlight>
{{out}}
<pre>2013-11-02
Line 1,637 ⟶ 2,895:
 
===Version 2===
<langsyntaxhighlight PLlang="pl/Ii"> df: proc Options(Main);
declare day_of_week(7) character(9) varying initial(
'Sunday','Monday','Tuesday','Wednesday',
Line 1,652 ⟶ 2,910:
put edit(month(substr(today,1,2)),' ',substr(today,3,2),', ',
substr(today,5,4))(A);
End;</langsyntaxhighlight>
{{out}}
<pre>2013-11-02
Line 1,658 ⟶ 2,916:
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell">"{0:yyyy-MM-dd}" -f (Get-Date)
"{0:dddd, MMMM d, yyyy}" -f (Get-Date)
# or
(Get-Date).ToString("yyyy-MM-dd")
(Get-Date).ToString("dddd, MMMM d, yyyy")</langsyntaxhighlight>
''Note:'' The names of months and days follow the currently set locale but otherwise the format is unchanged.
 
=={{header|Prolog}}==
 
{{works with|SWI-Prolog|6}}
 
<syntaxhighlight lang="prolog">
display_date :-
get_time(Time),
format_time(atom(Short), '%Y-%M-%d', Time),
format_time(atom(Long), '%A, %B %d, %Y', Time),
format('~w~n~w~n', [Short, Long]).
</syntaxhighlight>
 
=={{header|PureBasic}}==
{{works with|PureBasic|4.41}}
<langsyntaxhighlight PureBasiclang="purebasic">;Declare Procedures
Declare.s MonthInText()
Declare.s DayInText()
Line 1,707 ⟶ 2,977:
EndSelect
ProcedureReturn m$
EndProcedure</langsyntaxhighlight>
 
=={{header|Prolog}}==
 
{{works with|SWI-Prolog|6}}
 
<lang prolog>
display_date :-
get_time(Time),
format_time(atom(Short), '%Y-%M-%d', Time),
format_time(atom(Long), '%A, %B %d, %Y', Time),
format('~w~n~w~n', [Short, Long]).
</lang>
 
=={{header|Python}}==
Formatting rules: http://docs.python.org/lib/module-time.html (strftime)
 
<langsyntaxhighlight lang="python">import datetime
today = datetime.date.today()
# The first requested format is a method of datetime objects:
# This one is built in:
print today.isoformat()
# For full flexibility, use the strftime formatting codes from the link above:
# Or use a format string for full flexibility:
print today.strftime('"%Y-A, %m-B %d', %Y")</lang>
# This mechanism is integrated into the general string formatting system.
# You can do this with positional arguments referenced by number
"The date is {0:%A, %B %d, %Y}".format(d)
# Or keyword arguments referenced by name
"The date is {date:%A, %B %d, %Y}".format(date=d)
# Since Python 3.6, f-strings allow the value to be inserted inline
f"The date is {d:%A, %B %d, %Y}"
</syntaxhighlight>
 
=={{header|R}}==
strftime is short for "string format time".
<langsyntaxhighlight lang="rsplus">now <- Sys.time()
strftime(now, "%Y-%m-%d")
strftime(now, "%A, %B %d, %Y")</langsyntaxhighlight>
 
=={{header|Racket}}==
Line 1,749 ⟶ 3,015:
See: http://srfi.schemers.org/srfi-19/srfi-19.html
 
<langsyntaxhighlight lang="racket">#lang racket
(require srfi/19)
 
Line 1,761 ⟶ 3,027:
(displayln (date->string (current-date) "~A, ~B ~d, ~Y"))
;;; ~e is space padded day of month:
(displayln (date->string (current-date) "~A, ~B ~e, ~Y"))</langsyntaxhighlight>
both ~d and ~e satisfy the format required, since the "10" part of that date is 2-digit
 
Line 1,768 ⟶ 3,034:
Tuesday, April 02, 2013
Tuesday, April 2, 2013</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
{{libheader|DateTime&#58;&#58;Format}}
<syntaxhighlight lang="raku" line>use DateTime::Format;
 
my $dt = DateTime.now;
 
say strftime('%Y-%m-%d', $dt);
say strftime('%A, %B %d, %Y', $dt);</syntaxhighlight>
 
The built-in Date and DateTime classes both offer support for the ISO format:
<syntaxhighlight lang="raku" line>my $d = Date.today;
 
say $d.yyyy-mm-dd;</syntaxhighlight>
 
They don't include the longer format specified in the task, but you can always roll your own formatter instead of importing the library:
 
<syntaxhighlight lang="raku" line>my @months = <January February March April May June July
August September October November December>;
my @days = <Monday Tuesday Wednesday Thursday Friday Saturday Sunday>;
my $us-long = sub ($self) { "{@days[$self.day-of-week - 1]}, {@months[$self.month - 1]} {$self.day}, {$self.year}" };
my $d = Date.today :formatter($us-long);
 
say $d.yyyy-mm-dd; # still works
say $d; # uses our formatter sub</syntaxhighlight>
 
=={{header|Raven}}==
<syntaxhighlight lang ="raven">time int as today</langsyntaxhighlight>
 
Short form:
 
<langsyntaxhighlight lang="raven">today '%Y-%m-%d' date</langsyntaxhighlight>
 
Long form:
 
<langsyntaxhighlight lang="raven">today '%A, %B %d, %Y' date</langsyntaxhighlight>
 
=={{header|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">REBOL [
Title: "Date Formatting"
Author: oofoe
Date: 2009-12-06
URL: http://rosettacode.org/wiki/Date_format
]
Line 1,805 ⟶ 3,095:
pick system/locale/months now/month " "
now/day ", " now/year
]</langsyntaxhighlight>
 
{{out}}
Line 1,811 ⟶ 3,101:
2009-12-06
Sunday, December 6, 2009</pre>
=={{header|RED}}==
<syntaxhighlight lang="red">
Red []
;; zeropad
f2n: func [d] [ if d > 9 [return d ] append copy "0" d ]
 
d: now/date
 
print rejoin [d/year "-" f2n d/month "-" f2n d/day]
print rejoin [system/locale/days/(d/weekday) ", " system/locale/months/(d/month) " " f2n d/day ", " d/year]
</syntaxhighlight>
{{out}}<pre>2020-03-25
Wednesday, March 25, 2020
</pre>
=={{header|REXX}}==
REXX has a number of ways to obtain the various components of the current date (indeed, any date).
<br>It's up to the programmer to choose whatever version of the &nbsp; '''date''' &nbsp; BIF that best serves the purpose.
===idiomatic version===
<langsyntaxhighlight REXXlang="rexx">/*REXX pgm shows current date: yyyy-mm-dd & Dayofweek, Month dd, yyyy*/
x = date('S') /*get current date as yyyymmdd */
yyyy = left(x,4) /*pick off year (4 digs).*/
Line 1,827 ⟶ 3,130:
zdd = dd+0 /*remove leading zero from DD */
say weekday',' month zdd"," yyyy /*format date as: Month dd, yyyy*/
/*stick a fork in it, we're done.*/</langsyntaxhighlight>
{{out}}
<pre>
Line 1,835 ⟶ 3,138:
 
===compact version===
<langsyntaxhighlight lang="rexx">/*REXX pgm shows current date: yyyy-mm-dd & Dayofweek, Month dd, yyyy*/
/* ╔══════════════════════════════════════════════════════════════════╗
║ function returns a specific example ║
Line 1,862 ⟶ 3,165:
say date('W')"," date('M') word(date(), 1)"," yyyy
/* [↑] dayofweek Month dd, yyyy*/
/*stick a fork in it, we're done.*/</langsyntaxhighlight>
'''output''' would be the same as the 1<sup>st</sup> version.
 
===modern version===
This version can be used with those REXXes that support the &nbsp; '''I''' &nbsp; (ISO) parameter for the &nbsp; '''date''' &nbsp; BIF.
<langsyntaxhighlight REXXlang="rexx">/*REXX pgm shows current date: yyyy-mm-dd & Dayofweek, Month dd, yyyy*/
say date('I') /*yyyy-mm-dd with leading zeroes.*/
 
Line 1,873 ⟶ 3,176:
/* [↑] dayofweek Month dd, yyyy*/
/*stick a fork in it, we're done.*/
</syntaxhighlight>
</lang>
'''output''' would be the same as the 1<sup>st</sup> version.
<br><br>
 
=={{header|Ring}}==
<syntaxhighlight lang="c">
dtdateStr = listdate(21)
date1 = timelist()[19] + "-" + timelist()[10] + "-" + timelist()[6]
dt[1] = "abbreviated weekday name"
date2 = timelist()[2] + ", " + timelist()[4] + " " + timelist()[6] + ", " + timelist()[19] + nl
dt[2] = "full weekday name"
? dateStr
dt[3] = "abbreviated month name"
? date1
dt[4] = "full month name"
? date2
dt[5] = "Date & Time"
dt[6] = "Day of the month"
dt[7] = "Hour (24)"
dt[8] = "Hour (12)"
dt[9] = "Day of the year"
dt[10] = "Month of the year"
dt[11] = "Minutes after hour"
dt[12] = "AM or PM"
dt[13] = "Seconds after the hour"
dt[14] = "Week of the year (sun-sat)"
dt[15] = "day of the week"
dt[16] = "date"
dt[17] = "time"
dt[18] = "year of the century"
dt[19] = "year"
dt[20] = "time zone"
dt[21] = "percent sign"
 
/*
for i=1 to 21
timelist() ---> List contains the time and date information.
see dt[i] + " : " + TimeList () [i] + nl
Index Value
next
----------------------------
</lang>
1 - abbreviated weekday name
2 - full weekday name
3 - abbreviated month name
4 - full month name
5 - Date & Time
6 - Day of the month
7 - Hour (24)
8 - Hour (12)
9 - Day of the year
10 - Month of the year
11 - Minutes after hour
12 - AM or PM
13 - Seconds after the hour
14 - Week of the year (sun-sat)
15 - day of the week
16 - date
17 - time
18 - year of the century
19 - year
20 - time zone
21 - percent sign
*/
 
</syntaxhighlight>
{{out}}
<pre>
19/07/2020
2020-07-19
Sunday, July 19, 2020
</pre>
 
=={{header|RPL}}==
RPL can return the date as a floating point number (format dd.mmyyyy) and can convert it (along with the time) as a string (format "DAY dd.mm.yy hh.mm.ss")
To solve the task, some formatting is then needed.
{{works with|HP|48}}
≪ DATE DUP 1000000 * 10000 MOD "-" +
OVER FP 100 * IP + "-" +
SWAP IP +
≫ '<span style="color:blue">DTSHORT</span>' STO
≪ { "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday" }
{ "MON" "TUE" "WED" "THU" "FRI" "SAT" "SUN" }
DATE TIME TSTR 1 3 SUB POS GET ", " +
{ "January" "February" "March" "April" "May" "June" "July" "August" "September" "October" "November" "December"}
DATE FP 100 * IP GET + " " +
OVER IP + ", " +
DATE 1000000 * 10000 MOD +
≫ '<span style="color:blue">DTLONG</span>' STO
{{out}}
<pre>
2: "2023-8-17"
1: "Thursday, August 17, 2023"
</pre>
 
=={{header|Ruby}}==
Formatting rules: [//www.ruby-doc.org/core/Time.html#method-i-strftime Time#strftime]
 
<langsyntaxhighlight lang="ruby">puts Time.now
puts Time.now.strftime('%Y-%m-%d')
puts Time.now.strftime('%F') # same as %Y-%m-%d (ISO 8601 date formats)
puts Time.now.strftime('%A, %B %d, %Y')</langsyntaxhighlight>
{{out}}
<pre>
Line 1,923 ⟶ 3,263:
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic">'Display the current date in the formats of "2007-11-10" and "Sunday, November 10, 2007".
print date$("yyyy-mm-dd")
print date$("dddd");", "; 'return full day of the week (eg. Wednesday
print date$("mmmm");" "; 'return full month name (eg. March)
print date$("dd, yyyy") 'return day, year</langsyntaxhighlight>
{{out}}
<pre>
Line 1,935 ⟶ 3,275:
 
=={{header|Rust}}==
Using <code>chrono 0.4.6</code>
<lang rust>extern crate chrono;
<syntaxhighlight lang="rust">fn main() {
use chrono::*;
let now = chrono::Utc::now();
fn main(){
println!("{}", now.format("%Y-%m-%d"));
let now : DateTime<UTC> = UTC::now();
println!("{}", now.format("%Y-A, %m-B %d, %Y").to_string());
}</syntaxhighlight>
println!("{}", now.format("%A, %B %d, %Y").to_string());
}</lang>
 
=={{header|Scala}}==
<syntaxhighlight lang ="scala">val now=new Date()
import java.util.Date
 
val now=new Date()
println("%tF".format(now))
println("%1$tA, %1$tB %1$td, %1$tY".format(now))</langsyntaxhighlight>
 
{{out}}
<pre>
2023-04-17
Monday, April 17, 2023
</pre>
 
=={{header|Scheme}}==
Line 1,952 ⟶ 3,300:
{{works with|Guile|2.0.13}}
 
<langsyntaxhighlight Schemelang="scheme">(define short-date
(lambda (lt)
(strftime "%Y-%m-%d" (localtime lt))))
Line 1,969 ⟶ 3,317:
(display (long-date dt))(newline))))
 
</syntaxhighlight>
</lang>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "time.s7i";
Line 1,985 ⟶ 3,333:
writeln(strDate(now));
writeln(days[dayOfWeek(now)] <& ", " <& months[now.month] <& " " <& now.day <& ", " <& now.year);
end func;</langsyntaxhighlight>
 
=={{header|SenseTalk}}==
<syntaxhighlight lang="sensetalk">
put formattedTime( "[year]-[month]-[day]", the date)
 
put formattedTime( "[weekday], [month name] [day], [year]", the date)
</syntaxhighlight>
{{out}}
<pre>2019-12-18
Wednesday, December 18, 2019</pre>
 
=={{header|Shiny}}==
<langsyntaxhighlight lang="shiny">say time.format 'Y-m-d' time.now
say time.format 'l, F j, Y' time.now</langsyntaxhighlight>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">var time = Time.local;
say time.ctime;
say time.strftime("%Y-%m-%d");
say time.strftime("%A, %B %d, %Y");</langsyntaxhighlight>
{{out}}
<pre>
Line 2,006 ⟶ 3,364:
In Smalltalk, one sends a <tt>printFormat</tt> message to a Date object with year, month, and day. For other date strings, one must construct the date string from the parts of a Date object. Of course, you'd probably want to make a method for doing so.
 
<langsyntaxhighlight lang="smalltalk">| d |
| d |
d := Date today.
d printFormat: #(3 2 1 $- 1 1 2).
(d weekday asString), ', ', (d monthName), ' ', (d dayOfMonth asString), ', ', (d year asString)</syntaxhighlight>
{{works with|Smalltalk/X}}
</lang>
<syntaxhighlight lang="smalltalk">d := Date today.
d printOn:Stdout format:'%y-%m-%d'. Stdout cr.
d printOn:Stdout format:'%(DayName), %(MonthName) %d, %y' language:#en. Stdout cr.
d printOn:Stdout format:'%(DayName), %(MonthName) %d, %y' language:#de. Stdout cr.
d printOn:Stdout format:'%(DayName), %(MonthName) %d, %y' language:#fr. Stdout cr.</syntaxhighlight>
{{out}}
<pre>2020-12-17
Thursday, December 17, 2020
Donnerstag, Dezember 17, 2020
Vendredi, Décembre 17, 2020</pre>
 
=={{header|SparForte}}==
As a structured script. Does not use l10n package.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "dateformat")
@( description, "Display the current date in the formats of '2007-11-10' " )
@( description, "and 'Sunday, November 10, 2007'." )
@( see_also, "http://rosettacode.org/wiki/Date_format" )
@( "Ken O. Burtch" );
pragma license( unrestricted );
 
pragma restriction( no_external_commands );
 
procedure dateformat is
function Month_Image (Month : calendar.month_number) return string is
begin
case Month is
when 1 => return "January";
when 2 => return "February";
when 3 => return "March";
when 4 => return "April";
when 5 => return "May";
when 6 => return "June";
when 7 => return "July";
when 8 => return "August";
when 9 => return "September";
when 10 => return "October";
when 11 => return "November";
when others => return "December";
end case;
end Month_Image;
function Day_Image (Day : integer) return string is
begin
case Day is
when 0 => return "Monday";
when 1 => return "Tuesday";
when 2 => return "Wednesday";
when 3 => return "Thursday";
when 4 => return "Friday";
when 5 => return "Saturday";
when others => return "Sunday";
end case;
end Day_Image;
Today : constant calendar.time := calendar.clock;
begin
--put_line(
--Put_Line (Image (Today) (1..10));
 
put( calendar.year( Today ), "9999" ) @( "-" )
@( calendar.month( Today ), "99" ) @( "-" )
@( calendar.day( Today ), "99" );
new_line;
 
put_line(
Day_Image( calendar.day_of_week( Today ) ) & ", " &
Month_Image( calendar.month( Today ) ) &
strings.image( calendar.day( Today ) ) & "," &
strings.image( calendar.year( Today ) ) );
end dateformat;</syntaxhighlight>
 
=={{header|SQL}}==
{{works with|Oracle}}
<langsyntaxhighlight lang="sql">
select to_char(sysdate,'YYYY-MM-DD') date_fmt_1 from dual;
 
select to_char(sysdate,'fmDay, Month DD, YYYY') date_fmt_2 from dual;
</syntaxhighlight>
</lang>
 
<pre>
Line 2,036 ⟶ 3,462:
Formatting rules: http://www.standardml.org/Basis/date.html#SIG:DATE.fmt:VAL
 
<langsyntaxhighlight lang="sml">print (Date.fmt "%Y-%m-%d" (Date.fromTimeLocal (Time.now ())) ^ "\n");
print (Date.fmt "%A, %B %d, %Y" (Date.fromTimeLocal (Time.now ())) ^ "\n");</langsyntaxhighlight>
{{out}}
<pre>
Line 2,045 ⟶ 3,471:
 
=={{header|Stata}}==
 
<lang stata>display %tdCCYY-NN-DD td($S_DATE)
Stata has many ways to format dates, see [https://www.stata.com/help.cgi?Datetime_display_formats Datetime display formats] in the documentation.
display %tdDayname,_Month_dd,_CCYY td($S_DATE)</lang>
 
<syntaxhighlight lang="stata">display %tdCCYY-NN-DD td($S_DATE)
display %tdDayname,_Month_dd,_CCYY td($S_DATE)</syntaxhighlight>
 
=={{header|Suneido}}==
<langsyntaxhighlight Suneidolang="suneido">Date().Format('yyyy-MM-dd') --> "2010-03-16"
Date().LongDate() --> "Tuesday, March 16, 2010" </langsyntaxhighlight>
 
=={{header|Swift}}==
<langsyntaxhighlight Swiftlang="swift">import Foundation
extension String {
func toStandardDateWithDateFormat(format: String) -> String {
Line 2,062 ⟶ 3,492:
}
 
let date = "2015-08-28".toStandardDateWithDateFormat("yyyy-MM-dd")</langsyntaxhighlight>
 
{{out}}
Line 2,070 ⟶ 3,500:
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">set now [clock seconds]
puts [clock format $now -format "%Y-%m-%d"]
puts [clock format $now -format "%A, %B %d, %Y"]</langsyntaxhighlight>
 
=={{header|Terraform}}==
<syntaxhighlight lang="terraform">locals {
today = timestamp()
}
 
output "iso" {
value = formatdate("YYYY-MM-DD", local.today)
}
 
output "us-long" {
value = formatdate("EEEE, MMMM D, YYYY", local.today)
}</syntaxhighlight>
 
{{Out}}
<pre>Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
 
Outputs:
 
iso = 2020-09-16
us-long = Wednesday, September 16, 2020</pre>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
SET dayofweek = DATE (today,day,month,year,number)
Line 2,103 ⟶ 3,554:
PRINT format1
PRINT format2
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,111 ⟶ 3,562:
 
=={{header|UNIX Shell}}==
<langsyntaxhighlight lang="bash">date +"%Y-%m-%d"
date +"%A, %B %d, %Y"</langsyntaxhighlight>
 
On a new enough system <code>%F</code> is equivalent to <code>%Y-%m-%d</code>
<langsyntaxhighlight lang="bash">date +"%F"</langsyntaxhighlight>
 
<!-- ENHANCE-ME: what is new enough for %F ? For example it doesn't appear in these bits of POSIX,
Line 2,125 ⟶ 3,576:
{{works with|Cygnus/X Ursa}}
Cygnus/X Ursa can import and call Java classes.
<langsyntaxhighlight lang="ursa">cygnus/x ursa v0.78 (default, release 0)
[Oracle Corporation JVM 1.8.0_51 on Mac OS X 10.10.5 x86_64]
> import "java.util.Date"
Line 2,137 ⟶ 3,588:
> out (sdf.format d) endl console
Saturday, July 23, 2016
> _</langsyntaxhighlight>
 
=={{header|Ursala}}==
The method is to transform a date in standard format returned by the library function, now.
<langsyntaxhighlight Ursalalang="ursala">#import std
#import cli
 
Line 2,157 ⟶ 3,608:
#show+
 
main = <.text_form,numeric_form> now0</langsyntaxhighlight>
{{out}}
<pre>Wednesday, June 24, 2009
2009-06-24</pre>
 
=={{header|VB-DOS|PDS 7.1 BASIC}}==
{{works with|Visual Basic for DOS and PDS 7.1}}
<syntaxhighlight lang="vb">
OPTION EXPLICIT
 
' Months
DATA "January", "February", "March", "April", "May", "June", "July"
DATA "August", "September", "October", "November", "December"
 
' Days of week
DATA "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
 
' Var
DIM dDate AS DOUBLE, sMonth(1 TO 12) AS STRING, sDay(1 TO 7) AS STRING
DIM i AS INTEGER
 
' Read Names of months
FOR i = 1 TO 12
READ sMonth(i)
NEXT i
 
' Read Names of days
FOR i = 1 TO 7
READ sDay(i)
NEXT i
 
' Assign current date to a variable
dDate = NOW
 
CLS
PRINT "Rosettacode: Display the current date formatted."
PRINT
PRINT "Today's date: "; FORMAT$(dDate, "ddddd")
PRINT
PRINT "Use of values in the lists."
PRINT "Today is "; sDay(WEEKDAY(dDate)); ", "; sMonth(MONTH(dDate)); " "; FORMAT$(DAY(dDate)); ", "; FORMAT$(YEAR(dDate)); "."
PRINT
PRINT "Use of just the FORMAT$() function."
PRINT "Today is "; FORMAT$(dDate, "dddd, mmmm d, yyyy"); "."
 
END
</syntaxhighlight>
 
=={{header|VBA}}==
 
<langsyntaxhighlight VBAlang="vba">Function DateFormats()
Debug.Print Format(Date, "yyyy-mm-dd")
Debug.Print Format(Date, "dddd, mmmm dd yyyy")
End Function</langsyntaxhighlight>
 
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
<lang vb>
'YYYY-MM-DD format
WScript.StdOut.WriteLine Year(Date) & "-" & Right("0" & Month(Date),2) & "-" & Right("0" & Day(Date),2)
Line 2,177 ⟶ 3,670:
'Weekday_Name, Month_Name DD, YYYY format
WScript.StdOut.WriteLine FormatDateTime(Now,1)
</syntaxhighlight>
</lang>
 
{{Out}}
Line 2,188 ⟶ 3,681:
Display current date in format "2007-11-10":
 
<langsyntaxhighlight lang="vedit">Date(REVERSE+NOMSG+VALUE, '-')</langsyntaxhighlight>
 
Display current date in format "Sunday, November 10, 2007" (Requires VEDIT 6.2):
<langsyntaxhighlight lang="vedit">// Get todays date into #1, #2, #3 and #7
#1 = Date_Day
#2 = Date_Month
Line 2,221 ⟶ 3,714:
 
// Display the date string
RT(1) M(", ") RT(2) M(" ") NT(#1, LEFT+NOCR) M(",") NT(#3)</langsyntaxhighlight>
 
To insert the date string into edit buffer instead of displaying it, replace the last line with this:
 
<langsyntaxhighlight lang="vedit">RI(1) IT(", ") RI(2) IT(" ") NI(#1, LEFT+NOCR) IT(",") NI(#3)</langsyntaxhighlight>
 
=={{header|Vim Script}}==
See `:help strftime` - this function uses the C strftime() arguments' format.
<syntaxhighlight lang="vim">
echo strftime("%Y-%m-%d")
echo strftime("%A, %B %d, %Y")
</syntaxhighlight>
 
=={{header|V (Vlang)}}==
 
<syntaxhighlight lang="v (vlang)">import time
 
fn main() {
println(time.now().custom_format("YYYY-MM-DD"))
println(time.now().custom_format("dddd, MMMM D, YYYY"))
}</syntaxhighlight>
{{out}}
<pre>
2011-12-02
Friday, December 2, 2011
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-date}}
Unless it is embedded in a host application, Wren currently has no direct way to obtain the current date. We therefore assume this is passed in by the user as a command line parameter.
<syntaxhighlight lang="wren">import "os" for Process
import "./date" for Date
 
var args = Process.arguments
if (args.count != 1) {
Fiber.abort("Please pass just the current date in yyyy-mm-dd format.")
}
var current = Date.parse(args[0])
System.print(current.format(Date.isoDate))
System.print(current.format("dddd|, |mmmm| |d|, |yyyy"))</syntaxhighlight>
 
{{out}}
<pre>
$ wren date_format.wren 2020-06-05
2020-06-05
Friday, June 5, 2020
</pre>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">include c:\cxpl\codes;
int CpuReg, Year, Month, Day, DName, MName, WDay;
[CpuReg:= GetReg; \access CPU registers
Line 2,246 ⟶ 3,781:
Text(0, DName(WDay)); Text(0, ", "); Text(0, MName(Month)); Text(0, " ");
IntOut(0, Day); Text(0, ", "); IntOut(0, Year); CrLf(0);
]</langsyntaxhighlight>
 
{{out}}
Line 2,253 ⟶ 3,788:
Tuesday, November 20, 2012
</pre>
 
=={{header|Yabasic}}==
<syntaxhighlight lang="yabasic">dim n$(1)
 
n = token(date$, n$(), "-")
 
print n$(4), "-", n$(2), "-", n$(3)
print nDay$(n$(5)), ", ", nMonth$(n$(6)), " ", n$(3), ", ", n$(4)
 
sub nDay$(n$)
switch n$
case "Mon": case "Fri": case "Sun": break
case "Tue": n$ = n$ + "s" : break
case "Wed": n$ = n$ + "nes" : break
case "Thu": n$ = n$ + "rs" : break
case "Sat": n$ = n$ + "ur" : break
default: n$ = "none" : break
end switch
return n$ + "day"
end sub
 
sub nMonth$(n$)
local month$(1), n
n = token("January, February, March, April, May, June, July, August, September, October, November, December", month$(), ", ")
n = instr("JanFebMarAprMayJunJulAugSepOctNovDec", n$)
return month$(int(n/3) + 1)
end sub</syntaxhighlight>
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">"%d-%02d-%02d".fmt(Time.Clock.localTime.xplode()).println()
//--> "2014-02-28" (ISO format)</langsyntaxhighlight>
Not quite but close. Even though localTime returns a 7 tuple (and xplode pushes all 7 as call args), fmt only eats what it needs.
<langsyntaxhighlight lang="zkl">Time.Date.prettyDay(Time.Clock.localTime.xplode())
//--> "Friday, the 28th of February 2014"</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">y,m,d:=Time.Clock.localTime; D:=Time.Date;
"%s, %s %d, %d".fmt(D.dayName(D.weekDay(y,m,d)),
D.monthName(m), d,y)
//-->"Friday, February 28, 2014"</langsyntaxhighlight>
 
=={{header|zonnon}}==
<langsyntaxhighlight lang="zonnon">
module Main;
import System;
Line 2,277 ⟶ 3,842:
System.Console.WriteLine("{0}, {1}",now.DayOfWeek,now.ToString("MMMM dd, yyyy"));
end Main.
</syntaxhighlight>
</lang>
{{Out}}
<pre>
890

edits