Date manipulation: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added/changed comments and whitespace, changed indentations.)
Line 1,789: Line 1,789:


=={{header|REXX}}==
=={{header|REXX}}==
This version only works with REXXes that support the '''DATE''' and '''TIME''' extended functions.
This version only works with REXXes that support the   '''date'''   and   '''time'''   extended functions.
<lang REXX>/*REXX pgm to add 12 hours to a date & time, showing the before & after.*/
<lang REXX>/*REXX program adds 12 hours to a given date and time, displaying the before and after.*/
aDate = 'March 7 2009 7:30pm EST'
aDate = 'March 7 2009 7:30pm EST' /*the original or base date to be used.*/

parse var aDate mon dd yyyy hhmm tz . /*obtain the various parts&pieces*/
mins = time('M',hhmm,'C') /*get the # minutes past midnight*/
parse var aDate mon dd yyyy hhmm tz . /*obtain the various parts and pieces. */

mins = mins + (12*60) /*add twelve hours to timestamp. */
nMins = mins // 1440 /*compute #min into same/next day*/
mins = time('M', hhmm, "C") /*get the number minutes past midnight.*/
days = mins % 1440 /*compute number of days "added".*/
mins = mins + (12*60) /*add twelve hours to the timestamp.*/
nMins = mins // 1440 /*compute number min into same/next day*/
aBdays = date('B',dd left(mon,3) yyyy) /*# of base days since REXX epoch*/
nBdays = aBdays + days /*now, add the # of days "added".*/
days = mins % 1440 /*compute number of days added to dats.*/
nDate = date(,nBdays,'B') /*calculate the new date (maybe).*/
aBdays = date('B', dd left(mon,3) yyyy) /*number of base days since REXX epoch.*/
nTime = time('C',nMins,'M') /* " " " time " */
nBdays = aBdays + days /*now, add the number of days added. */
nDate = date(,nBdays, 'B') /*calculate the new date (maybe). */
say aDate ' + 12 hours ───► ' ndate ntime tz /*display new timestamp.*/
/*stick a fork in it, we're done.*/</lang>
nTime = time('C', nMins, "M") /* " " " time " */

say aDate ' + 12 hours ───► ' ndate ntime tz /*display the new timestamp to console.*/
/*stick a fork in it, we're all done. */</lang>
{{out}}
{{out}}
<pre style="overflow:scroll">
<pre style="overflow:scroll">