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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System date format

Status
Not open for further replies.

PeteJohnston

Programmer
Nov 6, 2002
291
GB
This is a follow-on from a thread about adding to the system time.

When I (and a few others by the look of that thread) want to convert a date held on a file to output it on a screen/report it is usually a case of calling an API or a CL-pgm to get the system date format then using select/when to decide which format (*MDY, *DMY, *EUR....) to use when doing the move. I've just discovered that there is a *JOBRUN parameter which automatically uses the job's date format without having to do the call and Select-group.
Code:
C    *JOBRUN      Move   CharDate    DateField
This is probably old news to you all but it may help someone in the future. PeteJ
(Contract Code-monkey)

It's amazing how many ways there are to skin a cat
(apologies to the veggies)
 
That should work for most people, but remember, it is possible to change a job (CHGJOB command, the DATFMT parameter) to have a date format which does not equal the system's date format.

What I'm getting at is: don't confuse system date format with job date format. Two different animals (on most systems, they are the same; but I imagine on some mult-national systems, there could be problems).
"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
I don't think I would ever confuse the two, I've just never come across anyone having the need to change the job date format to something different from the system date format.

I know it can be done, but users would be unlikely to do this and most programmers would be unlikely to change it either. I've not been able to think of a reason why I would want to change it, mult-nationals or not. I'm currently contracting for part of the British Oxygen Group who have 11 AS400s in 5 countries and I haven't found anyone in the department who has thought it necessary (or desirable) to use CHGJOB DATFMT(*xxx) in any code so far.

When I am signed on to one of their American boxes I can't think why a job I am running should be run with *DMY just because I'm sitting in an office in England. PeteJ
(Contract Code-monkey)

It's amazing how many ways there are to skin a cat
(apologies to the veggies)
 
I just use the %DATE bif to get the date, by default, this format the date to *ISO. If I want to change the date format, I define a new DATE data type in a 'D' spec, with a different DATFMT. Look at the code below:

Code:
D DateUSA          D DatFmt(*USA)
D DateISO          D DatFmt(*ISO)
.
.
.
/Free

  DateISO = %Date();  // this returns the current date
  DateUSA = DateISO;  // this converts the ISO date into USA
  DateUSA = %Date();  // or you could just load the DateUSA field directly

/End-Free
RedMage1967
IBM Certifed - RPG IV Progammer
 
RedMage
I think you maybe missed the original point. If you're writing code which will be multi-national, the USA date format is not always the system date format for the country which you are in. This means that when you have used a date field to do some arithmetic and want to use that field in the outside world you should move it into the local date format. The code I was working on submitted a batch job after a delay which was retrieved from a file. Since the data was held in *CYMD format, the date arithmetic was simple but the SBMJOB command needs the SCDDATE parameter to be in the system date format. Your code is Okay in the USA, but I'm writing code in the UK which will be used in Europe (*EUR or *DMY), USA (*MDY), Japan and Korea (both *ISO). *JOBRUN avoids the need to define dates in different formats and decide which one to use based on the job (or system?) date format.

flapeyre
Your point about system versus job date format might apply here. What happens if you do CHGJOB DATFMT(*DMY) when the system is *MDY? Does the SCDDATE parm for SBMJOB need to be in *DMY or *MDY?

RedMage1967
Which release did %Date arrive? I can't get the editor to recognise it. PeteJ
(Contract Code-monkey)

It's amazing how many ways there are to skin a cat
(apologies to the veggies)
 
I've just checked it out. If you change the job date format, submit job needs the SCDDATE parameter to be in the job date format, not the system. PeteJ
(Contract Code-monkey)

It's amazing how many ways there are to skin a cat
(apologies to the veggies)
 
The %Date bif became available at release V5R1.
 
PeteJohnston

Using the %Date bif and the date data type, you can change the date formats in a RPG 4 (V5R1 or later) to whatever date format you need. That's what I was trying to say. (And yes, I did miss your original point, sorry about that). RedMage1967
IBM Certifed - RPG IV Progammer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top