Using Date Diff In Where Of Query

GC2010

Registered User.
Local time
Today, 13:03
Joined
Jun 3, 2019
Messages
120
I have a short text field that I am parsing out the month from. I then want to use it as part of my where clause

I have this syntax but am getting data type mismatch...but am a i not converting it to date format so the DateDiff function should work?

Code:
Select * from teamroster 
where DateDiff(‘m’, CDate(Mid([action date],InStrRev([action date], ‘ ‘) + 1)), Now()) > 7;
 
What is in [action date]? Is it a date?
 
What is in [action date]? Is it a date?

No. Action date is short text that contains for example:

Need forms Jul

The one factor that is always the same is the last 3 characters is always the date.
 
In case I’m going about this the wrong way. I want to return all records where the month is current month or prior
 
the last 3 characters is always the date.

"Jul" is not a date, it's a month. CDate() can't convert it to a date, as you also need day and year to make a complete date. Do you have multiple year's data? How would you tell July 2018 from 2019?
 
"Jul" is not a date, it's a month. CDate() can't convert it to a date, as you also need day and year to make a complete date. Do you have multiple year's data? How would you tell July 2018 from 2019?

The year is stored in a separate field, called year. Lol

Yeah...the dev of this SharePoint site didn’t set it up all to well imho
 
I'll say. How do you name a field "ActionDate" that contains "Need forms Jul". Well, this works:

?cdate("jul 1, 2019")
7/1/2019

so you could build a string with the result of your Mid() function concatenated with ", 1," and the value from your year field.
 
I'll say. How do you name a field "ActionDate" that contains "Need forms Jul". Well, this works:

?cdate("jul 1, 2019")
7/1/2019

so you could build a string with the result of your Mid() function concatenated with ", 1," and the value from your year field.[/QUOTE

Does it matter if I use 1 or 01?
 
I doubt it, but it would be pretty easy to test. ;)
 
I doubt it, but it would be pretty easy to test. ;)

Now that I've solved my issue, I'll post as to why I was asking :banghead:

I originally thought you were telling me to build my date string in the DateDiff function like this:
Code:
Select * from teamroster 
where DateDiff(‘m’, CDate(Mid([action date],InStrRev([action date], ‘ ‘) + 1) & "/01/" & [Year]), Now()) > 7;

but that was still giving me skewed results. Then I realized I was just being stupid :eek:

And I needed to create an Alias in the query to do

Code:
Dates: DateDiff(‘m’, CDate(Mid([action date],InStrRev([action date], ‘ ‘) + 1) & "/01/" & [Year]), Now())

Then add a WHERE clause onto that to say
Code:
<=DateValue(CStr(Now()))

And of course now I'm getting my desired results.
 
This is jumping through hoops:

<=DateValue(CStr(Now()))

Try just

<=Date()
 

Users who are viewing this thread

Back
Top Bottom