Difference in Days between two date fields.

agreenvbman's Avatar, Join Date: Aug 2009
Newbie Member
Hello,

I have to find the difference between two date fields. I have a system date which I have defined as Date in my form. I also have a Date Modified field. I want to subtract the Date Field from the date Modified field and get a total days variable. I will use this Total Days variable in an If Statement to determine whether other fields can be changed or not. I do not want any field changed after five days on the form. If the the TotalDays variable equals 5, I will not let any changes be saved. If the TotalDays is less than five, I will let changes be made to fields.

Is there a way in VB to do this?

agreenvbman
0
nimesh's Avatar, Join Date: Apr 2009
Invasive contributor
you should get the result by a direct subtract statement
Did you already tried it?
0
agreenvbman's Avatar, Join Date: Aug 2009
Newbie Member
I am trying to use a Sequel Server 2005 database table called CallIssueMain to find the records with DateTimeAdded less than 6 days.

I am trying to write the Tsequel coding like this, but getting an error. What is wrong with my coding inside the Query window?

The Coding:

Declare @EndDate smalldatetime, @StartDate smalldatetime

set @StartDate = dateadd(dd,-6,getdate())
set @EndDate = getdate()

Select ID, Issue, Resolution, DateTimeAdded,FROM CallIssueMainWHERE User= @UserName and Date between @StartDate and @EndDate



The error I get is:

ERROR PARSING QUERY.[TOKEN LINE NUMBER = 1, TOKEN LINE OFFSET = 1, TOKEN IN ERROR = DECLARE]
ERROR SOURCE: ADO.NET DATA PROVIDER
0
nimesh's Avatar, Join Date: Apr 2009
Invasive contributor
Looks like its the problem in the Declare statement
TOKEN IN ERROR = DECLARE

Check if this helps:
http://www.experts-exchange.com/Prog..._24479076.html
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
experts-exchange.com will not allow to see the answer unless you are an expert member or paid member.
0
nimesh's Avatar, Join Date: Apr 2009
Invasive contributor
Quote:
Originally Posted by shabbir View Post
experts-exchange.com will not allow to see the answer unless you are an expert member or paid member.
Yes, that's true
but today after your reply I found something which I didn't noticed earlier

If you go to expert-exchange from google it shows you the answer at the bottom of the page, but if you go directly, then it doesn't

check the attached page which I got after googling

till now even I was in question whether they have changed the policy or is it just me than I can see the answers.

it might be only 2-3 times that I was unable to see the answer, but most of the time I did see.
I think google is the reason
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
I never scrolled that down but yes may be may be not. Who cares. I believe in information and knowledge should be open to all.