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

Between Current date AND Current date subtract 5

Status
Not open for further replies.

Corflex

Technical User
May 16, 2002
14
Per 9.6

I want the last 5 days in a query.

I have the following and it works:
OEINVH.INVDATE BETWEEN 20090525 AND 20090529

I also have used this for current date only and it works:
OEINVH.INVDATE >= {*FormatedCurrentDate}


Now I want BETWEEN current date AND current date minus 5

How can I do this?

 
sorry, didn't work.

This works BUT no idea how to get the minus 5 in there:
AND OEINVH.INVDATE BETWEEN {*FormatedCurrentDate} AND {*FormatedCurrentDate}

I tried
{*FormatedCurrentDate} -5
 
What do you mean it didn't work? Was there an error? Did it give incorrect results?
Actually, looking at your first post, I see that the dates don't seem to be in the PSQL date format. You might have to do some date and string functions.
How are you generating "{*FormatedCurrentDate}"?

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
 
This is from Accpac and dates are stored as numbers in YYYYMMDD format, so deducting 5 will not work.
 
mirtheil, you pointed me in the right direction. I look at "{*FormatedCurrentDate}" and copied it, minus 5 in the new one and it worked great.

Thank you
 
I spoke to soon...
It works if the dates land correctly:

Ex (works fine)
{*FormatedCurrentDate} = 20090529
{*FormatedCurrentDate-5} = 20090524

Ex that doesnt work
Ex
{*FormatedCurrentDate} = 20090601
{*FormatedCurrentDate-5} = 20090596 <--(96 instead of 24)

Any way to get around this?
 
How do you generate the {*FormatedCurrentDate}?

You'll probably need to take the current date, subtract 5, then convert it to the "Formatted" version. How you do that will depend on the programming environment you're using.

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
 
It is formatted as:

FormatDateYYYYMMDD(GlobalFields.Item("MCURYEAR"),GlobalFields.Item("MCURMONTH"),GlobalFields.Item("MCURDAY"))

Below is the above vaules
MCURYEAR - Year(Date())
MCURMONTH - Month(Date())
MCURDAY - Day(Date())
 
I've used the following code in MSSQL to add 30 days to the date. It isn't pretty but might give you a starting point:

cast(convert(varchar(8),CONVERT(datetime, CAST(audtdate AS char(8))) + 30,112) as int)

However, if you are generating the code to automate Accpac then you should need to worry about parsing that request. You should be able to format your date parameters based on your query. e.g.:

sql = "OEINVH.INVDATE BETWEEN " & format(StartingDate -5, "yyyymmdd") & " AND " & format(StartingDate, "yyyymmdd")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top