View previous topic :: View next topic
Author
Message
nkothako Active User Joined: 26 Nov 2008Posts: 125 Location: chennai
How to get previous date of current date
How to get next date of current date
How to get month first date of current date
How to get last month of current date
Always my input will be yyyymmdd format, need output format should be YYYYDDD using rexx
Back to top
superk Global Moderator Joined: 26 Apr 2004Posts: 4652 Location: Raleigh, NC, USA
Have you looked up the usage of the Date Function ?
Anyway, the first two are easy:
Code:
/* REXX */
thedate = ... /* Date in YYYYMMDD format */
basedate = Date(B,thedate,S)
prevdate = Date(S,basedate-1,B)
prevyyyy = Left(prevdate,4)
nextdate = Date(S,basedate+1,B)
nextyyyy = Left(nextdate,4)
Say 'Current Date:'thedate
Say 'Previous Date:'||prevyyyy||Right(Date(D,prevdate,S),3,'0')
Say 'Next Date:'||nextyyyy||Right(Date(D,nextdate,S),3,'0')
I'm not clear what you mean by the next two:
How to get month first date of current date
How to get last month of current date
Back to top
enrico-sorichetti Superior Member Joined: 14 Mar 2007Posts: 10873 Location: italy
Code:
#! /opt/ooRexx/bin/rexx
/*REXX - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
Trace "O"
say "*********** " "previous day"
say "day date(-1)-s " date("S",date("b")-1,"b")
say "day date(-1)-j " left(date("s",date("b")-1,"b"),4) || right(date("d",date("b")-1,"b"),3,"0")
say "*********** " "current day"
say "day date()-s " date("S")
say "day date()-j " left(date("S"),4) || right(date("d"),3,"0")
say "*********** " "next day"
say "day date(+1)-s " date("S",date("b")+1,"b")
say "day date(+1)-j " left(date("s",date("b")+1,"b"),4) || right(date("d",date("b")+1,"b"),3,"0")
parse value date("s") with 1 y 5 m 7 .
fdcm = y || m || "01"
py = y
pm = m - 1
if pm = 0 then do
pm = 12
py = py - 1
end
fdpm = py || pm || "01"
ny = y
nm = m + 1
if nm = 13 then do
nm = "01"
ny = ny + 1
end
fdnm = ny || nm || "01"
wy = ny
wm = nm + 1
if wm = 13 then do
wm = "01"
wy = wy + 1
end
fdwm = wy || wm || "01"
say "*********** " "previous month"
say "first -s " fdpm
say "first -j " left(fdpm,4) || right(date("d",fdpm,"s"),3,"0")
say "last -s " date("S",date("b",fdcm,"s")-1,"b")
say "day -j " left(date("S",date("b",fdcm,"s")-1,"b"),4) || right(date("d",date("b",fdcm,"s")-1,"b"),3,"0")
say "*********** " "current month"
say "first -s " fdcm
say "first -j " left(fdcm,4) || right(date("d",fdcm,"s"),3,"0")
say "last -s " date("S",date("b",fdnm,"s")-1,"b")
say "day -j " left(date("S",date("b",fdnm,"s")-1,"b"),4) || right(date("d",date("b",fdnm,"s")-1,"b"),3,"0")
say "*********** " "next month"
say "first -s " fdnm
say "first -j " left(fdnm,4) || right(date("d",fdnm,"s"),3,"0")
say "last -s " date("S",date("b",fdwm,"s")-1,"b")
say "day -j " left(date("S",date("b",fdwm,"s")-1,"b"),4) || right(date("d",date("b",fdwm,"s")-1,"b"),3,"0")
exit
Back to top
Please enable JavaScript!