Solved

Compare Dates

Posted on 2011-09-15
9
335 Views
Last Modified: 2012-05-12
Hi Experts:

The problem that I am running into is: I'm comparing two dates and if the date field (NEWWE) is less than PASTWE date plus thirteen weeks it should display the NEWWE date else display zero.  It is working for the most part but a NEWWE date of 09/18/2011 < 12/11/2011 is returning a value of 0 when it should return the NEWWE value.  The following is the Iif statement I'm using.

IIf([NewWe]<DateAdd("ww",13,[PASTWE]),[NewWe],0)

What am I doing wrong?  Thanks!
0
Comment
Question by:CompTech810
[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
  • 5
  • 4
9 Comments
 
LVL 18

Accepted Solution

by:
Cluskitt earned 125 total points
ID: 36543162
That is because it's treating your dates as strings. Use CDate():

IIf(CDate([NewWe])<DateAdd("ww",13,CDate([PASTWE])),CDate([NewWe]),0)
0
 
LVL 2

Author Comment

by:CompTech810
ID: 36543179
Ahh...  That worked with the exception of the '0' displays as: 12/30/1899
0
 
LVL 18

Expert Comment

by:Cluskitt
ID: 36543220
Yes. A date with the value of 0 is that. You can, however, simply remove the last CDate. You only need it to compare. Afterwards, you can return it as a string. If you need the value as a date later, you can always use CDate then.
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 2

Author Comment

by:CompTech810
ID: 36543608
Great that worked.

I do have an additional question.  In the criteria of the query that we just did I only want to display dates that are greater than zero.  When I use the criteria to only include records greater than zero it prompts me for NEWWE.

>0
0
 
LVL 18

Expert Comment

by:Cluskitt
ID: 36543663
Well, without looking at your file, it's hard to know what went wrong. You can have a look at the SQL to see if anything is amiss. Without knowing what you did, I can't really help you. But if you just add:
>0
in the criteria field, I don't see a reason why it shouldn't work.
0
 
LVL 2

Author Comment

by:CompTech810
ID: 36544797
I'm not sure either.  Is there a way to run debug to check what access is doing?
0
 
LVL 2

Author Comment

by:CompTech810
ID: 36545728
I submitted a question with the criteria issue.  I have tried everything I can think of.

Thanks for your help!
0
 
LVL 18

Expert Comment

by:Cluskitt
ID: 36547836
Glad to help. As for the debug part, you can't really debug SQL. What you can do is check the SQL query (I assume you were doing this in the graphic structure window). Then you, or someone here, can assist you with it.
0
 
LVL 2

Author Comment

by:CompTech810
ID: 36548497
Thanks!!
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

630 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