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 first 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.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchEnterpriseLinux

SearchDataCenter

Close