RPGIV @ Work

A unique site for RPG and System i Lovers


Hi, this site will provide all what you need in System i and RPG developments.

My Name is Chamara Withanachchi, System i Expert and RPG Developer. And in the field for last 11 years.

I hope you will find lot of valuable information from this site

Date/Time Functions Print E-mail
User Rating: / 0
Written by Chamara Withanachchi   

IBM introduced the %DATE, %TIME, and %TIMESTAMP built-in functions even before V5.1 and /FREE syntax. this will replace the TIME opcode, and also you can do more using these

Builtin functions


to use these built-in functions, you simply declare a date, time, or timestamp variable and then use the EVAL opcode to copy the value into the variable. For example:

D myDat           S               D       
		D myTim           S               T       
			 myDate = %date();  // current system date
			 myTime = %time();  // current system time

Get the Job Date

To retrieve the job date instead of the system date To accomplish this with the built-in functions, you need to go back in time and dust off the UDATE figurative constant and wrap it

in %DATE, see following example


D myDate          S               D       
			 myDate = %date(UDATE);  // job date       


You can use the TIME opcode to populate timestamp fields just like date and time fields. However, you can also use the %TIMESTAMP built-in function with identical results. for example:


FUserMast UF A E           K DISK            
		D myDate          S               D       
		   crtdate = %timestamp();  // timestamp            
		   write custRec;       

%TimeStamp() returns 26 characters of information: the date and the time with six characters of microseconds; however, only three digits of the microseconds (i.e., milliseconds)

are accurate, the remaining three are always set to zero.