DateDiff programming problem
Author Message
DateDiff programming problem

Hi All,

I recently installed a function to find the difference
between two dates for the work week (I got the program
and how to use it from a couple sources on this BB).  The
program works nicely, except if there is a blank field
for the one of the dates, then I'll get an error.  I was
hoping to get around this with a simple If...Then
statement, looking for a null value, then ending the
program.  Apparently, a lot has changed since I studied
programming in high school and I can't do this.  Are
there any suggestions out there?  Thank you very much in

Fri, 18 Nov 2005 19:31:40 GMT
DateDiff programming problem
Hi:

You could use the IsDate function to check if valid date
like this --

Dim dt as Date, dt1 as Date
Dim dblDiff as double

dt = CDate("1/1/1990")
dt1 = CDate("1/5/1990")

if isdate(dt) and isdate(dt1) then
dblDiff = DateDiff("d",dt1,dt)
else
dbldiff = 0
end if

Msgbox dblDiff

Quote:
>-----Original Message-----
>Hi All,

>I recently installed a function to find the difference
>between two dates for the work week (I got the program
>and how to use it from a couple sources on this BB).  The
>program works nicely, except if there is a blank field
>for the one of the dates, then I'll get an error.  I was
>hoping to get around this with a simple If...Then
>statement, looking for a null value, then ending the
>program.  Apparently, a lot has changed since I studied
>programming in high school and I can't do this.  Are
>there any suggestions out there?  Thank you very much in
>.

Fri, 18 Nov 2005 20:18:46 GMT
DateDiff programming problem
Thanks!  I'll give it a shot.
Quote:
>-----Original Message-----
>Hi:

>You could use the IsDate function to check if valid date
>like this --

>Dim dt as Date, dt1 as Date
>Dim dblDiff as double

>dt = CDate("1/1/1990")
>dt1 = CDate("1/5/1990")

>if isdate(dt) and isdate(dt1) then
>  dblDiff = DateDiff("d",dt1,dt)
>else
>  dbldiff = 0
>end if

>Msgbox dblDiff

>>-----Original Message-----
>>Hi All,

>>I recently installed a function to find the difference
>>between two dates for the work week (I got the program
>>and how to use it from a couple sources on this BB).
The
>>program works nicely, except if there is a blank field
>>for the one of the dates, then I'll get an error.  I
was
>>hoping to get around this with a simple If...Then
>>statement, looking for a null value, then ending the
>>program.  Apparently, a lot has changed since I studied
>>programming in high school and I can't do this.  Are
>>there any suggestions out there?  Thank you very much
in
>>.

>.

Fri, 18 Nov 2005 21:48:40 GMT
DateDiff programming problem
Hi Ya!
I am actually trying to find a function that gives me the
difference between two dates from two seperate tables and
returns the most current date of the two.
Do you happen to know what would be the best route for
this?
Starting with an original due date in one table that
doesn't change.
Then in a seperate table there is a date field that you
can enter varying dates that may be older than the
What I need is to calculate the original date with the
most current date from all the other dates in table two
and come up with the date that gives me the most time.
Any suggestions would be greatly apprciated.
Thanks!!
Quote:
>-----Original Message-----
>Thanks!  I'll give it a shot.
>>-----Original Message-----
>>Hi:

>>You could use the IsDate function to check if valid date
>>like this --

>>Dim dt as Date, dt1 as Date
>>Dim dblDiff as double

>>dt = CDate("1/1/1990")
>>dt1 = CDate("1/5/1990")

>>if isdate(dt) and isdate(dt1) then
>>  dblDiff = DateDiff("d",dt1,dt)
>>else
>>  dbldiff = 0
>>end if

>>Msgbox dblDiff

>>>-----Original Message-----
>>>Hi All,

>>>I recently installed a function to find the difference
>>>between two dates for the work week (I got the program
>>>and how to use it from a couple sources on this BB).
>The
>>>program works nicely, except if there is a blank field
>>>for the one of the dates, then I'll get an error.  I
>was
>>>hoping to get around this with a simple If...Then
>>>statement, looking for a null value, then ending the
>>>program.  Apparently, a lot has changed since I studied
>>>programming in high school and I can't do this.  Are
>>>there any suggestions out there?  Thank you very much
>in
>>>.

>>.

>.

Sat, 19 Nov 2005 02:58:23 GMT
DateDiff programming problem
On Mon, 2 Jun 2003 11:58:23 -0700, "Susannah"

Quote:

>Hi Ya!
>I am actually trying to find a function that gives me the
>difference between two dates from two seperate tables and
>returns the most current date of the two.

Those are two quite separate issues.

DateDiff("d", [table1].[datefield], [table2].[datefield])

will give the number of days difference between the two;

IIF([Table1].[Datefield] > [Table2].[Datefield], [Table1].[Datefield],
[Table2.Datefield])

will return the more recent of the two dates.

Quote:
>Do you happen to know what would be the best route for
>this?
>Starting with an original due date in one table that
>doesn't change.
>Then in a seperate table there is a date field that you
>can enter varying dates that may be older than the

How are the tables related? If you have multiple records in each
table, which date do you want to compare with which? I'm assuming that
you can create a Query JOINING the two tables, but your message
doesn't indicate that you're doing so.

Quote:
>What I need is to calculate the original date with the
>most current date from all the other dates in table two
>and come up with the date that gives me the most time.
>Any suggestions would be greatly apprciated.
>Thanks!!

John W. Vinson[MVP]
Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public

Sat, 19 Nov 2005 05:30:42 GMT
DateDiff programming problem
After looking at this, I don't think this is what I
need.  What I need is for the function to check to see if
there is a null value in the field and end itself if
there is, so I don't get an error.  I know with the old
(old, old, old) BASIC language I could end a program with
an If...Then statement (If..statement is true or false,
Then End, and that would end the program) apparently this
is not the case with VB or I just can't find the right
syntax.  Am I missing something?
Quote:
>-----Original Message-----
>Hi:

>You could use the IsDate function to check if valid date
>like this --

>Dim dt as Date, dt1 as Date
>Dim dblDiff as double

>dt = CDate("1/1/1990")
>dt1 = CDate("1/5/1990")

>if isdate(dt) and isdate(dt1) then
>  dblDiff = DateDiff("d",dt1,dt)
>else
>  dbldiff = 0
>end if

>Msgbox dblDiff

>>-----Original Message-----
>>Hi All,

>>I recently installed a function to find the difference
>>between two dates for the work week (I got the program
>>and how to use it from a couple sources on this BB).
The
>>program works nicely, except if there is a blank field
>>for the one of the dates, then I'll get an error.  I
was
>>hoping to get around this with a simple If...Then
>>statement, looking for a null value, then ending the
>>program.  Apparently, a lot has changed since I studied
>>programming in high school and I can't do this.  Are
>>there any suggestions out there?  Thank you very much
in
>>.

>.

Sat, 19 Nov 2005 19:07:35 GMT
DateDiff programming problem

Quote:
>After looking at this, I don't think this is what I
>need.  What I need is for the function to check to see if
>there is a null value in the field and end itself if
>there is, so I don't get an error.

Something like

If IsNull(Me!controlname) Then Exit Sub

should do the trick for you.

John W. Vinson[MVP]
Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public

Sun, 20 Nov 2005 02:10:53 GMT

 Page 1 of 1 [ 7 post ]

Relevant Pages