Solved

DatePart for Two Months Ago

Posted on 2009-07-13
10
443 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 19

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 19

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 500 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

617 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