Solved

DatePart for Two Months Ago

Posted on 2009-07-13
10
442 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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 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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a mirrored QA test site 2 93
EF5 How do I stop pre-compiled views? 8 54
SQL Server 2014 Express vs Full - Service Pack question 5 47
Performance Issue in Oracle 3 46
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…

734 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