Solved

DatePart for Two Months Ago

Posted on 2009-07-13
10
430 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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 100

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction: Often, when running a query with joins, the results show up "duplicates", and often, those duplicates can be "eliminated" in the results using DISTINCT, for example. Using DISTINCT is simple: just add it after the SELECT keyword, an…
In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data 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…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now