INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Between Current date AND Current date subtract 5

Between Current date AND Current date subtract 5

(OP)
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?

 

RE: Between Current date AND Current date subtract 5

Try something like:
OEINVH.INVDATE BETWEEN now() - 5 AND now()

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
http://www.mirtheil.com

RE: Between Current date AND Current date subtract 5

(OP)
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

RE: Between Current date AND Current date subtract 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
http://www.mirtheil.com

RE: Between Current date AND Current date subtract 5

This is from Accpac and dates are stored as numbers in YYYYMMDD format, so deducting 5 will not work.

RE: Between Current date AND Current date subtract 5

(OP)
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

RE: Between Current date AND Current date subtract 5

(OP)
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?

RE: Between Current date AND Current date subtract 5

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
http://www.mirtheil.com

RE: Between Current date AND Current date subtract 5

(OP)
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())

RE: Between Current date AND Current date subtract 5

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")

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close