Returns the current date.
Today()
Type Returned:
Date
Object: Procedure, Transaction, Web Panel, Work Panel
Notes:
- In the iSeries environment, this function returns the start date of the job and not the System Date. This allows running a job with a date different from the current one and using it in the program.
- To use the actual System Date, see the Sysdate() function.
- In a PC environment, it returns the System Date so the Today and Sysdate functions are equivalent.
Consider the following Transaction object:
Customer
{
CustomerId*
CustomerName
CustomerPhone
CustomerDateOfBirth
CustomerAddedDate
}
1) In the Transaction Rules Tab, you can define the following rules:
Default(CustomerDateOfBirth, Today());
Error("The date of birth cannot be higher than today.") if CustomerDateOfBirth > Today();
The Default rule is only triggered when inserting a new record. So, the first rule initializes the CustomerDateOfBirth attribute with the current date as the default and the end user may change the value.
The second rule validates whether the CustomerDateOfBirth is higher than today. If so, it displays an error text.
2) In addition, in the same Transaction Rules Tab you may define the following rules:
Default(CustomerAddedDate, Today());
Noaccept(CustomerAddedDate);
This Default rule initializes the CustomerAddedDate attribute with the current date as default. In turn, the NoAccept rule disables the edition of the CustomerAddedDate attribute. Therefore, the CustomerAddedDate attribute is set to the current date and that value can't be updated.
3) Now, consider a Web Panel object that contains a &StartDate variable and a button in its Web Layout. The end user must enter a date in the variable, and when clicking on the button, the associated event has to validate whether the &StartDate is empty or higher than the current date. If none of these things occur, all the customers inserted from the &StartDate value onwards must be navigated and some action must be performed.
The event associated with the button contains the following code:
Event 'Processes customers'
If &DateFrom.IsEmpty()
msg("The date must not be empty")
Else
If &DateFrom > Today()
msg("The date must not be higher than today")
else
For each Customer
where CustomerAddedDate < &DateFrom
//do something
endfor
endif
endif
Endevent
Sysdate function
GxRemove variable