Q

Running AS/400 query to find records based on date

Learn about a quick way of running an AS/400 query to select records based on current sysdate.

Is there a quick way of running an AS/400 query to select records based on current sysdate? I know you can get...

the current date using the Current command, but I can’t figure out how to make this work.

Try the following AS/400 query to find selected records based on date.

In "Define result fields" :

Field Expression
CD CHAR(CURRENT(DATE))
CURDAT SUBSTR(CD, 1, 2) ||
SUBSTR(CD, 4, 2) ||
SUBSTR(CD, 7, 2)

Then use CURDAT in your selection. You may have to change the day/month/year sequence to match your date field.

You can also expand the query to compare days, for example, today and yesterday’s data, using the following:

YD char(current(date) - 1 DAYS)

YESDAT SUBSTR(YD, 1, 2) ||
SUBSTR(YD, 4, 2) ||
SUBSTR(YD, 7, 2)

More on AS/400 commands:

Note: This tip is a compilation of advice from various experts on our site.

This was last published in February 2012

Dig Deeper on iSeries SQL commands and statements

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchEnterpriseLinux

SearchDataCenter

Close