Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DatePart for Two Months Ago

Posted on 2009-07-13
10
Medium Priority
?
451 Views
Last Modified: 2012-05-07
Hello Experts,

Can you give me the formula I would use in the Crystal Reports record selection to return records for two months ago?
I attempted to find it myself searching on 'DatePart', but gave up.

Thank you, Chopp
0
Comment
Question by:Chopp
  • 4
  • 3
  • 2
  • +1
10 Comments
 

Author Comment

by:Chopp
ID: 24844409
Or do I need 'dateadd' or 'dateadd' AND 'datepart' together?

I will appreciate your help!
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24845269
Hope this is what you meant:

where date_column >= dateadd(mm, -2, date_column)
0
 

Author Comment

by:Chopp
ID: 24845565
If I use that record selection, I get ALL the months greater than two months ago, and I only want records from two months ago.

For instance, if I run the report today, I only want records from May.
Any other ideas to get those records?

Thank you, Chopp
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24845901
Oops.. a typo as I Just typed in a hurry. And it was

where date_column <= dateadd(mm, -2, date_column)

>> For instance, if I run the report today, I only want records from May.

This made me to analyse a little bit further

-- if You want to get records before 1st of July including all records from May then

where date_column < dateadd(mm,-1, datediff(mm,0, YOURDATE))

-- if You want to get records before 1st of May then

where date_column < dateadd(mm,-2, datediff(mm,0, YOURDATE))

Hope this helps
0
 
LVL 20

Expert Comment

by:NerdsOfTech
ID: 24847449
1 month data from your date entered
WHERE date_column <= dateadd(mm,-1, datediff(mm,0, YOURDATE))
AND date_column >= dateadd(mm,-2, datediff(mm,0, YOURDATE))

Open in new window

0
 
LVL 20

Expert Comment

by:NerdsOfTech
ID: 24847459
WHERE date_column < dateadd(mm,-1, datediff(mm,0, YOURDATE))
AND date_column >= dateadd(mm,-2, datediff(mm,0, YOURDATE))
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 24856226
You have been given a lot of options

If noe of thise work, what exactly do you need if you run the report on 15 Juy 2009?

mlmcc
0
 

Author Comment

by:Chopp
ID: 24878378
Hello,

I am still hoping for assistance...

{Cases.DateOpened} <= dateadd("m", -2, currentdate) - This selection returned all months before June.

{Cases.DateOpened} < dateadd("m",-1, datediff("m",0, currentdate)) - This selection gave me the following error message for the "0" "A date is required here".

{Cases.DateOpened} <= dateadd("m",-1, datediff("m",0, currentdate))
AND {Cases.DateOpened} >= dateadd("m",-2, datediff("m",0, currentdate)) - This selection gave the same error message as above.

My goal is to return records for the full month which is 2 months ago from the current month.

Thank you, Chopp
0
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 2000 total points
ID: 24879277
Have you tried out this one mentioned above:

WHERE date_column < dateadd(mm,-1, datediff(mm,0, YOURDATE))
AND date_column >= dateadd(mm,-2, datediff(mm,0, YOURDATE))

Else try this one out:

where year(date_column) >= year(dateadd(mm, -2, getdate()))
AND month(date_column) <= month(dateadd(mm, -2, getdate()))
0
 

Author Comment

by:Chopp
ID: 24880023
Thank you very much for the last example.  I am only using the equals sign in order to get only the records from 2 months ago.  It appears to be working!  Do you know how to resolve the error message that is displayed when using the first example? The error highlights the zero, and states, 'A date is required here'.

Again, thank you very much for this help!
~Chopp

year({IIncident.I_tTimeTransmit}) = year(dateadd("m", -2, currentdate())) and
month({IIncident.I_tTimeTransmit}) = month(dateadd("m", -2, currentdate()))
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question