Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dates

Status
Not open for further replies.

K1ng

Programmer
Jul 2, 2002
2
GB
Ok, my task is to create a program to delete any files that havn't been accessed in 6 months, I get this data as follows:-

filedate = stream("filename.tmp", 'c', 'QUERY TIMESTAMP')

I want to then compare it to the current date, aquired as follows:-

today = Date('Standard')

But, I cant do this because they are different formats, I have tried changing the format of the date but I'm not sure If I'm doing it correctly.

Could anyone please tell me how to mathimatically compare these two values within REXX.

Thanks in advance for any help.
K1ng

 
today=Date('S') returns the date in the format 'yyyymmdd'.

I assume you are using IBM's ObjREXX under Windows, and so

filedate = stream("filename.tmp", 'c', 'QUERY TIMESTAMP')

returns the timestamp in the format 'yyyy-mm-dd hh:mm:ss'. You can extract the date from the timestamp and convert it to 'S' format with:

fdate = substr(filedate,1,4) || substr(filedate,6,2) || substr(9,2)

This is not necessarily the most elegant method, but it is fairly easy to understand. Hope this helps. Roger.

 
Hallo K1ng,

I have just read your posting once again and would like to point out the use of the Date() function with 3 arguments for converting from one date format to another. Also the use of 'B' (Base) format which returns the number of days since the arbitrary base date of 1 Jan 0001. This 'B' format is extremely useful for calculating date differences:
Code:
/* Is file older than 6 Months (180 days)?  */
file = 'DATE.REX'  
filedate = stream(file, 'c', 'QUERY TIMESTAMP')
filedate = substr(filedate,1,4)|| ,
           substr(filedate,6,2)|| ,   
           substr(filedate,9,2)
filedate = date('B',filedate,'S')
today    = date('B')
say filedate today
If (today - filedate)> 180 Then Do
  say file 'is older than 6 months'
End
 
I got it fixed and my solution was much the same as yours, if only a bit clunky-er.

/* My solution */
filedate = stream(Files.Counter, 'c', 'QUERY TIMESTAMP')

filedate = word(filedate, 1)
Position = pos("-", filedate)
filedate = delstr(filedate, position, 1)
Position = pos("-", filedate)
filedate = delstr(filedate, position, 1)
filedate = date('Base', filedate, 'Standard')

today = Date('Base')
If (today - filedate) > 180 then do
/* And so on and so on */

I'm still trying to optimise it though because its running on a 60GB share so it takes a while.

K1ng
 
If you are using ObjREXX you can use the nonstandard (i.e. on Windows, Unix but not on MVS, VM etc.) changestr() function. Sorry, I should have thought of this in my first appends :cool:
Code:
filedate = word(filedate, 1)
filedate = changestr('-', filedate, '') 
/* above, '' = zero length string */
filedate = date('B',filedate,'S')
/* and so on */
According to the manual:
Code:
CHANGESTR(needle,haystack,newneedle)
Returns a copy of haystack in which newneedle replaces all occurrences of needle.


 
Status
Not open for further replies.

Similar threads

Replies
5
Views
558
Replies
3
Views
145

Part and Inventory Search

Sponsor

Back
Top