Date Difference

juneau730

Board Regular
Joined
Jun 7, 2018
Messages
68
I am sure this can be done, but I am not able to find anything specifically addressing it.

Is there a way to create a DateDiff parameter in a query, where is it calculating the days, between current date and a date field within the table the query is built from?
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,129
Office Version
365
Platform
Windows
If I am understanding you correctly, you should be able to do this in a calculated field in a query, i.e.
Code:
DaysPassed: Date() - [[COLOR=#ff0000][I]DateField[/I][/COLOR]]
Where DateField is the name of your date field.
If the dates in that field are future dates, you will probably want to reverse the order and subtract Date() (which returns the current date) from the date field.
 

juneau730

Board Regular
Joined
Jun 7, 2018
Messages
68
Thanks Joe4, worked like a champ!

If I am understanding you correctly, you should be able to do this in a calculated field in a query, i.e.
Code:
DaysPassed: Date() - [[COLOR=#ff0000][I]DateField[/I][/COLOR]]
Where DateField is the name of your date field.
If the dates in that field are future dates, you will probably want to reverse the order and subtract Date() (which returns the current date) from the date field.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,129
Office Version
365
Platform
Windows
You are welcome.
 

juneau730

Board Regular
Joined
Jun 7, 2018
Messages
68
You are welcome.
A quick follow-up question.
The day count is displaying a number sort of like this, 123.45678
Even when I set the decimal to 0 in the field properties on the form, it doesn't go away.
Any thoughts on how to remove it?
 

welshgasman

Well-known Member
Joined
May 25, 2013
Messages
677
PMFJI,

You probably have a time element in your date field.?

Use the Int() function to jusy get the integer of the value.?

HTH
 

juneau730

Board Regular
Joined
Jun 7, 2018
Messages
68
You are correct some of the data fields do have a time element in them. Those that don't reflect the date diff correctly.
I'm not sure how to set the INT() to return that. Sorry still learning some of this

PMFJI,

You probably have a time element in your date field.?

Use the Int() function to just get the integer of the value.?

HTH
 

xenou

MrExcel MVP, Moderator
Joined
Mar 2, 2007
Messages
16,508
Example:
Code:
Expr1: Date()-Int([DateField])
Also:
Code:
Expr2: DateDiff("d",[DateField],Date())
 

juneau730

Board Regular
Joined
Jun 7, 2018
Messages
68
Sorry for the delay in replying to you all. I wanted to take a minute and thank you all for your assistance, not just with this question, but with all the others I have posted. With your help, not only is this one small issue corrected, but as a whole the dBase is much more functional and user friendly.
 

Forum statistics

Threads
1,077,721
Messages
5,335,812
Members
399,051
Latest member
WPO

Some videos you may like

This Week's Hot Topics

Top