Subtracting date and time values

C

Calvin Shane

My client is using Access to provide dates and times on
equipment failures (using Date and Time opened as one
field, and date and time closed as one field (date and
time separated by a space, in the following format:

Date closed field is mm/dd/yyyy hh:mm AM/PM
Date opened field is same as above.

Instead of using Excel (currently), he wants Access to
produce Mean Time Between Failures (MTBF), which is the
date/time closed of the next record, minus date/time
opened of the previous record (record -1), and produce
result in the line of previous record, and so on. MTBF
will not be produced for the 1st record, but will
thereafter. I've learned about using "Datediff", but
currently have no PC with Access to test it. With these
formats, is it possible using "Datediff" to produce a
result in hours/minutes or hours.hundredth hours (like
1.2 hours)?
 
T

Tom Ellison

Dear Calvin:

How about using Datediff to get the difference in minutes, and divide
by 60, or in seconds and divide by 3600? Then you'd have hours with a
decimal point. Taking the integer and fraction parts of this, you'd
have hours and fractions of an hour. Multiply the fraction by 60 and
get minutes, with decimals again.

Should not be hard to do.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 
C

Calvin

Thank you...My question is how to get the current
record's Date Opened, minus the previous record's Date
Closed?

"Datediff(excuse the syntax)[DateOpened] - ([DateClosed]-
1)"
to denote the previous record. The result goes on the
line of the current record.

Does this involve having to use Visual Basic, or SQL?
Also, this is a query, that will eventually be used in a
report (summing the MTBF's and averaging them).

CALVIN
 
T

Tom Ellison

Dear Calvin:

The problem of getting the value from the previous record is a
separate one from what I addressed. To retrieve the previous record
would require a correlated subquery.

In order to be able to do this, you must uniquely define how to
retrieve the previous record, based on the data it contains. By
uniquely I mean that, given your definition, there can be at most one
row that meets that definition.

Let's work first on a query that can retrieve and display this value
from the previous row. The rest is easy.

Please provide the SQL for a query that provides everything except
this previous Date Closed. This query should be sorted so the rows
are in the order that defines which is the previous row.

I'll try to take if from there and show how this can be done.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


Thank you...My question is how to get the current
record's Date Opened, minus the previous record's Date
Closed?

"Datediff(excuse the syntax)[DateOpened] - ([DateClosed]-
1)"
to denote the previous record. The result goes on the
line of the current record.

Does this involve having to use Visual Basic, or SQL?
Also, this is a query, that will eventually be used in a
report (summing the MTBF's and averaging them).

CALVIN
-----Original Message-----
Dear Calvin:

How about using Datediff to get the difference in minutes, and divide
by 60, or in seconds and divide by 3600? Then you'd have hours with a
decimal point. Taking the integer and fraction parts of this, you'd
have hours and fractions of an hour. Multiply the fraction by 60 and
get minutes, with decimals again.

Should not be hard to do.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts



.
 
C

Calvin Shane

Thanks, Tom...Is there a phone number to reach you? I
know Access, but don't know SQL as well, but I'll give it
my best shot.

CALVIN
-----Original Message-----
Dear Calvin:

The problem of getting the value from the previous record is a
separate one from what I addressed. To retrieve the previous record
would require a correlated subquery.

In order to be able to do this, you must uniquely define how to
retrieve the previous record, based on the data it contains. By
uniquely I mean that, given your definition, there can be at most one
row that meets that definition.

Let's work first on a query that can retrieve and display this value
from the previous row. The rest is easy.

Please provide the SQL for a query that provides everything except
this previous Date Closed. This query should be sorted so the rows
are in the order that defines which is the previous row.

I'll try to take if from there and show how this can be done.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


Thank you...My question is how to get the current
record's Date Opened, minus the previous record's Date
Closed?

"Datediff(excuse the syntax)[DateOpened] - ([DateClosed]-
1)"
to denote the previous record. The result goes on the
line of the current record.

Does this involve having to use Visual Basic, or SQL?
Also, this is a query, that will eventually be used in a
report (summing the MTBF's and averaging them).

CALVIN
-----Original Message-----
Dear Calvin:

How about using Datediff to get the difference in minutes, and divide
by 60, or in seconds and divide by 3600? Then you'd have hours with a
decimal point. Taking the integer and fraction parts
of
this, you'd
have hours and fractions of an hour. Multiply the fraction by 60 and
get minutes, with decimals again.

Should not be hard to do.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts

On Tue, 23 Mar 2004 22:08:03 -0800, "Calvin Shane"

My client is using Access to provide dates and times on
equipment failures (using Date and Time opened as one
field, and date and time closed as one field (date and
time separated by a space, in the following format:

Date closed field is mm/dd/yyyy hh:mm AM/PM
Date opened field is same as above.

Instead of using Excel (currently), he wants Access to
produce Mean Time Between Failures (MTBF), which is the
date/time closed of the next record, minus date/time
opened of the previous record (record -1), and produce
result in the line of previous record, and so on. MTBF
will not be produced for the 1st record, but will
thereafter. I've learned about using "Datediff", but
currently have no PC with Access to test it. With these
formats, is it possible using "Datediff" to produce a
result in hours/minutes or hours.hundredth hours (like
1.2 hours)?

.

.
 
C

Calvin Shane

Additional information, Date Closed and Date Opened are
entered into the Access database (not generated, I don't
think). I'll get back with you on the query.

Thanks, again.

CALVIN
-----Original Message-----
Dear Calvin:

The problem of getting the value from the previous record is a
separate one from what I addressed. To retrieve the previous record
would require a correlated subquery.

In order to be able to do this, you must uniquely define how to
retrieve the previous record, based on the data it contains. By
uniquely I mean that, given your definition, there can be at most one
row that meets that definition.

Let's work first on a query that can retrieve and display this value
from the previous row. The rest is easy.

Please provide the SQL for a query that provides everything except
this previous Date Closed. This query should be sorted so the rows
are in the order that defines which is the previous row.

I'll try to take if from there and show how this can be done.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


Thank you...My question is how to get the current
record's Date Opened, minus the previous record's Date
Closed?

"Datediff(excuse the syntax)[DateOpened] - ([DateClosed]-
1)"
to denote the previous record. The result goes on the
line of the current record.

Does this involve having to use Visual Basic, or SQL?
Also, this is a query, that will eventually be used in a
report (summing the MTBF's and averaging them).

CALVIN
-----Original Message-----
Dear Calvin:

How about using Datediff to get the difference in minutes, and divide
by 60, or in seconds and divide by 3600? Then you'd have hours with a
decimal point. Taking the integer and fraction parts
of
this, you'd
have hours and fractions of an hour. Multiply the fraction by 60 and
get minutes, with decimals again.

Should not be hard to do.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts

On Tue, 23 Mar 2004 22:08:03 -0800, "Calvin Shane"

My client is using Access to provide dates and times on
equipment failures (using Date and Time opened as one
field, and date and time closed as one field (date and
time separated by a space, in the following format:

Date closed field is mm/dd/yyyy hh:mm AM/PM
Date opened field is same as above.

Instead of using Excel (currently), he wants Access to
produce Mean Time Between Failures (MTBF), which is the
date/time closed of the next record, minus date/time
opened of the previous record (record -1), and produce
result in the line of previous record, and so on. MTBF
will not be produced for the 1st record, but will
thereafter. I've learned about using "Datediff", but
currently have no PC with Access to test it. With these
formats, is it possible using "Datediff" to produce a
result in hours/minutes or hours.hundredth hours (like
1.2 hours)?

.

.
 
C

Calvin Shane

Tom, I do have some sample data, and I can remember the
original query that my client was going to use.

I'll get back with you on both. Would you like for me to
mail you a sample of the data, or would that be necessary?

CALVIN
-----Original Message-----
Dear Calvin:

The problem of getting the value from the previous record is a
separate one from what I addressed. To retrieve the previous record
would require a correlated subquery.

In order to be able to do this, you must uniquely define how to
retrieve the previous record, based on the data it contains. By
uniquely I mean that, given your definition, there can be at most one
row that meets that definition.

Let's work first on a query that can retrieve and display this value
from the previous row. The rest is easy.

Please provide the SQL for a query that provides everything except
this previous Date Closed. This query should be sorted so the rows
are in the order that defines which is the previous row.

I'll try to take if from there and show how this can be done.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


Thank you...My question is how to get the current
record's Date Opened, minus the previous record's Date
Closed?

"Datediff(excuse the syntax)[DateOpened] - ([DateClosed]-
1)"
to denote the previous record. The result goes on the
line of the current record.

Does this involve having to use Visual Basic, or SQL?
Also, this is a query, that will eventually be used in a
report (summing the MTBF's and averaging them).

CALVIN
-----Original Message-----
Dear Calvin:

How about using Datediff to get the difference in minutes, and divide
by 60, or in seconds and divide by 3600? Then you'd have hours with a
decimal point. Taking the integer and fraction parts
of
this, you'd
have hours and fractions of an hour. Multiply the fraction by 60 and
get minutes, with decimals again.

Should not be hard to do.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts

On Tue, 23 Mar 2004 22:08:03 -0800, "Calvin Shane"

My client is using Access to provide dates and times on
equipment failures (using Date and Time opened as one
field, and date and time closed as one field (date and
time separated by a space, in the following format:

Date closed field is mm/dd/yyyy hh:mm AM/PM
Date opened field is same as above.

Instead of using Excel (currently), he wants Access to
produce Mean Time Between Failures (MTBF), which is the
date/time closed of the next record, minus date/time
opened of the previous record (record -1), and produce
result in the line of previous record, and so on. MTBF
will not be produced for the 1st record, but will
thereafter. I've learned about using "Datediff", but
currently have no PC with Access to test it. With these
formats, is it possible using "Datediff" to produce a
result in hours/minutes or hours.hundredth hours (like
1.2 hours)?

.

.
 
T

Tom Ellison

Dear Calvin:

If you feel there are things we cannot accomplish in the newsgroup,
you may email me first. Please explain why you feel we need to speak
by phone. I can then reply with my phone if you have convinced me.

So you understand, most of us answering questions here are volunteers
who try to make a living as well. In the newsgroup, we can answer
questions as time permits, or ignore the questions when we're to busy.
So, we can get a tiny bit touchy about making deeper commitments.

I personally try to spread my limited time so I can help the largest
number of people. The newsgroups are the best venue for that, so
stick it out in here if you can.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


Thanks, Tom...Is there a phone number to reach you? I
know Access, but don't know SQL as well, but I'll give it
my best shot.

CALVIN
-----Original Message-----
Dear Calvin:

The problem of getting the value from the previous record is a
separate one from what I addressed. To retrieve the previous record
would require a correlated subquery.

In order to be able to do this, you must uniquely define how to
retrieve the previous record, based on the data it contains. By
uniquely I mean that, given your definition, there can be at most one
row that meets that definition.

Let's work first on a query that can retrieve and display this value
from the previous row. The rest is easy.

Please provide the SQL for a query that provides everything except
this previous Date Closed. This query should be sorted so the rows
are in the order that defines which is the previous row.

I'll try to take if from there and show how this can be done.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


Thank you...My question is how to get the current
record's Date Opened, minus the previous record's Date
Closed?

"Datediff(excuse the syntax)[DateOpened] - ([DateClosed]-
1)"
to denote the previous record. The result goes on the
line of the current record.

Does this involve having to use Visual Basic, or SQL?
Also, this is a query, that will eventually be used in a
report (summing the MTBF's and averaging them).

CALVIN
-----Original Message-----
Dear Calvin:

How about using Datediff to get the difference in
minutes, and divide
by 60, or in seconds and divide by 3600? Then you'd
have hours with a
decimal point. Taking the integer and fraction parts of
this, you'd
have hours and fractions of an hour. Multiply the
fraction by 60 and
get minutes, with decimals again.

Should not be hard to do.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts

On Tue, 23 Mar 2004 22:08:03 -0800, "Calvin Shane"

My client is using Access to provide dates and times on
equipment failures (using Date and Time opened as one
field, and date and time closed as one field (date and
time separated by a space, in the following format:

Date closed field is mm/dd/yyyy hh:mm AM/PM
Date opened field is same as above.

Instead of using Excel (currently), he wants Access to
produce Mean Time Between Failures (MTBF), which is the
date/time closed of the next record, minus date/time
opened of the previous record (record -1), and produce
result in the line of previous record, and so on. MTBF
will not be produced for the 1st record, but will
thereafter. I've learned about using "Datediff", but
currently have no PC with Access to test it. With
these
formats, is it possible using "Datediff" to produce a
result in hours/minutes or hours.hundredth hours (like
1.2 hours)?

.

.
 
T

Tom Ellison

Dear Shane:

I was suggesting all you need to do is post the SQL as I described and
answer a couple of questions. I have had good success answering
correlated subquery questions in this newsgroup just based on that.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


Tom, I do have some sample data, and I can remember the
original query that my client was going to use.

I'll get back with you on both. Would you like for me to
mail you a sample of the data, or would that be necessary?

CALVIN
-----Original Message-----
Dear Calvin:

The problem of getting the value from the previous record is a
separate one from what I addressed. To retrieve the previous record
would require a correlated subquery.

In order to be able to do this, you must uniquely define how to
retrieve the previous record, based on the data it contains. By
uniquely I mean that, given your definition, there can be at most one
row that meets that definition.

Let's work first on a query that can retrieve and display this value
from the previous row. The rest is easy.

Please provide the SQL for a query that provides everything except
this previous Date Closed. This query should be sorted so the rows
are in the order that defines which is the previous row.

I'll try to take if from there and show how this can be done.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


Thank you...My question is how to get the current
record's Date Opened, minus the previous record's Date
Closed?

"Datediff(excuse the syntax)[DateOpened] - ([DateClosed]-
1)"
to denote the previous record. The result goes on the
line of the current record.

Does this involve having to use Visual Basic, or SQL?
Also, this is a query, that will eventually be used in a
report (summing the MTBF's and averaging them).

CALVIN
-----Original Message-----
Dear Calvin:

How about using Datediff to get the difference in
minutes, and divide
by 60, or in seconds and divide by 3600? Then you'd
have hours with a
decimal point. Taking the integer and fraction parts of
this, you'd
have hours and fractions of an hour. Multiply the
fraction by 60 and
get minutes, with decimals again.

Should not be hard to do.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts

On Tue, 23 Mar 2004 22:08:03 -0800, "Calvin Shane"

My client is using Access to provide dates and times on
equipment failures (using Date and Time opened as one
field, and date and time closed as one field (date and
time separated by a space, in the following format:

Date closed field is mm/dd/yyyy hh:mm AM/PM
Date opened field is same as above.

Instead of using Excel (currently), he wants Access to
produce Mean Time Between Failures (MTBF), which is the
date/time closed of the next record, minus date/time
opened of the previous record (record -1), and produce
result in the line of previous record, and so on. MTBF
will not be produced for the 1st record, but will
thereafter. I've learned about using "Datediff", but
currently have no PC with Access to test it. With
these
formats, is it possible using "Datediff" to produce a
result in hours/minutes or hours.hundredth hours (like
1.2 hours)?

.

.
 
C

Calvin Shane

Thanks, Tom. This is my first time in a Newsgroup such
as this...I'm also getting into a time conflict, because
I want to get this problem solved soon for my client. I
apologize for any inconvenience. I also have to find a
machine that has Access on it to be able to test, and
that also has a time limitation (like 5pm CT).

Anyway, I have been thinking about what you've said to
this point. It sounds as though I have to set up Date
Closed into another value, to be used later in
computation with the next Date Opened to produce MTBF
(Mean Time Between Failures). I have to brush up on my
SQL, too.

Let me get back with you, so that I can work on testing
and SQL. More later.
-----Original Message-----
Dear Calvin:

If you feel there are things we cannot accomplish in the newsgroup,
you may email me first. Please explain why you feel we need to speak
by phone. I can then reply with my phone if you have convinced me.

So you understand, most of us answering questions here are volunteers
who try to make a living as well. In the newsgroup, we can answer
questions as time permits, or ignore the questions when we're to busy.
So, we can get a tiny bit touchy about making deeper commitments.

I personally try to spread my limited time so I can help the largest
number of people. The newsgroups are the best venue for that, so
stick it out in here if you can.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


Thanks, Tom...Is there a phone number to reach you? I
know Access, but don't know SQL as well, but I'll give it
my best shot.

CALVIN
-----Original Message-----
Dear Calvin:

The problem of getting the value from the previous record is a
separate one from what I addressed. To retrieve the previous record
would require a correlated subquery.

In order to be able to do this, you must uniquely
define
how to
retrieve the previous record, based on the data it contains. By
uniquely I mean that, given your definition, there can be at most one
row that meets that definition.

Let's work first on a query that can retrieve and display this value
from the previous row. The rest is easy.

Please provide the SQL for a query that provides everything except
this previous Date Closed. This query should be
sorted
so the rows
are in the order that defines which is the previous row.

I'll try to take if from there and show how this can
be
done.
Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Tue, 23 Mar 2004 22:57:57 -0800, "Calvin"

Thank you...My question is how to get the current
record's Date Opened, minus the previous record's Date
Closed?

"Datediff(excuse the syntax)[DateOpened] - ([DateClosed]-
1)"
to denote the previous record. The result goes on the
line of the current record.

Does this involve having to use Visual Basic, or SQL?
Also, this is a query, that will eventually be used
in
a
report (summing the MTBF's and averaging them).

CALVIN
-----Original Message-----
Dear Calvin:

How about using Datediff to get the difference in
minutes, and divide
by 60, or in seconds and divide by 3600? Then you'd
have hours with a
decimal point. Taking the integer and fraction
parts
of
this, you'd
have hours and fractions of an hour. Multiply the
fraction by 60 and
get minutes, with decimals again.

Should not be hard to do.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts

On Tue, 23 Mar 2004 22:08:03 -0800, "Calvin Shane"

My client is using Access to provide dates and
times
on
equipment failures (using Date and Time opened as one
field, and date and time closed as one field (date and
time separated by a space, in the following format:

Date closed field is mm/dd/yyyy hh:mm AM/PM
Date opened field is same as above.

Instead of using Excel (currently), he wants Access to
produce Mean Time Between Failures (MTBF), which is the
date/time closed of the next record, minus date/time
opened of the previous record (record -1), and produce
result in the line of previous record, and so on. MTBF
will not be produced for the 1st record, but will
thereafter. I've learned about using "Datediff", but
currently have no PC with Access to test it. With
these
formats, is it possible using "Datediff" to produce a
result in hours/minutes or hours.hundredth hours (like
1.2 hours)?

.


.

.
 
C

Calvin Shane

Based upon some separate data that I've received from the
client, MTBF (Mean Time Between Failures) and MTTR (Mean
time to report) are on the fly. I am basing my first
query to address MTTR (DateClosed - DateCreated) to get
value in hours.hundredth hours, using:

MTTR: (Datediff("m", [DateClosed],[DateCreated]) /
60)
MTBF: (Datediff("m", [DateCreated],([DateClosed-1]) / 60

The results are "h.nn", where "h" is hours, and ".nn" are
in hundredths of an hour.

The question is, is the syntax correct to have
[DateClosed-1] to signify the nth-1 (or previous)
record? Would I instead have to reserve the DateClosed
somewhere else, to be used later to produce MTBF? After
thinking about it, I might have to, such as:

MTBFtest:[(Dateclosed) - 1], then use

MTBF: (Datediff("m",[DateCreated],[MTBFtest] / 60

The query would consist of:

SELECT
AssetID,WOID,AssetDescription,WOTypeDescription,DateCreate
d,DateClosed,MTTR,MTBF
from DataBase

Am I on the right track?

(Please also excuse the syntax on the Query
statements...I'm still working on that, too).

CALVIN

-----Original Message-----
Thanks, Tom. This is my first time in a Newsgroup such
as this...I'm also getting into a time conflict, because
I want to get this problem solved soon for my client. I
apologize for any inconvenience. I also have to find a
machine that has Access on it to be able to test, and
that also has a time limitation (like 5pm CT).

Anyway, I have been thinking about what you've said to
this point. It sounds as though I have to set up Date
Closed into another value, to be used later in
computation with the next Date Opened to produce MTBF
(Mean Time Between Failures). I have to brush up on my
SQL, too.

Let me get back with you, so that I can work on testing
and SQL. More later.
-----Original Message-----
Dear Calvin:

If you feel there are things we cannot accomplish in
the
newsgroup,
you may email me first. Please explain why you feel we need to speak
by phone. I can then reply with my phone if you have convinced me.

So you understand, most of us answering questions here are volunteers
who try to make a living as well. In the newsgroup, we can answer
questions as time permits, or ignore the questions when we're to busy.
So, we can get a tiny bit touchy about making deeper commitments.

I personally try to spread my limited time so I can
help
the largest
number of people. The newsgroups are the best venue
for
that, so
stick it out in here if you can.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


Thanks, Tom...Is there a phone number to reach you? I
know Access, but don't know SQL as well, but I'll give it
my best shot.

CALVIN
-----Original Message-----
Dear Calvin:

The problem of getting the value from the previous
record is a
separate one from what I addressed. To retrieve the
previous record
would require a correlated subquery.

In order to be able to do this, you must uniquely define
how to
retrieve the previous record, based on the data it
contains. By
uniquely I mean that, given your definition, there can
be at most one
row that meets that definition.

Let's work first on a query that can retrieve and
display this value
from the previous row. The rest is easy.

Please provide the SQL for a query that provides
everything except
this previous Date Closed. This query should be sorted
so the rows
are in the order that defines which is the previous row.

I'll try to take if from there and show how this can be
done.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Tue, 23 Mar 2004 22:57:57 -0800, "Calvin"

Thank you...My question is how to get the current
record's Date Opened, minus the previous record's Date
Closed?

"Datediff(excuse the syntax)[DateOpened] -
([DateClosed]-
1)"
to denote the previous record. The result goes on the
line of the current record.

Does this involve having to use Visual Basic, or SQL?
Also, this is a query, that will eventually be used in
a
report (summing the MTBF's and averaging them).

CALVIN
-----Original Message-----
Dear Calvin:

How about using Datediff to get the difference in
minutes, and divide
by 60, or in seconds and divide by 3600? Then you'd
have hours with a
decimal point. Taking the integer and fraction parts
of
this, you'd
have hours and fractions of an hour. Multiply the
fraction by 60 and
get minutes, with decimals again.

Should not be hard to do.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts

On Tue, 23 Mar 2004 22:08:03 -0800, "Calvin Shane"

My client is using Access to provide dates and times
on
equipment failures (using Date and Time opened as one
field, and date and time closed as one field (date
and
time separated by a space, in the following format:

Date closed field is mm/dd/yyyy hh:mm AM/PM
Date opened field is same as above.

Instead of using Excel (currently), he wants Access
to
produce Mean Time Between Failures (MTBF), which is
the
date/time closed of the next record, minus date/time
opened of the previous record (record -1), and
produce
result in the line of previous record, and so on.
MTBF
will not be produced for the 1st record, but will
thereafter. I've learned about using "Datediff", but
currently have no PC with Access to test it. With
these
formats, is it possible using "Datediff" to
produce
.
 
T

Tom Ellison

Dear Calvin:

You said:

I have to set up Date Closed into another value, to be used later in
computation with the next Date Opened to produce MTBF (Mean Time
Between Failures)

I'm not sure what you mean, but that doesn't sound like what I tried
to express.

Depending on whether you can uniquely define which is the "previous
record" determines by the data it contains, you don't have to do
anything extraordinary. I can provide you with the query to do this.

Just post a query that returns everything you need other than the
value from the previous record. Make sure it is ordered uniquely so
that the row from which you want to extract the Date Closed is the one
just before the one where you have the Date Opened. I'll add the Date
Closed value to the query, then you can get to work calculating on it.



Thanks, Tom. This is my first time in a Newsgroup such
as this...I'm also getting into a time conflict, because
I want to get this problem solved soon for my client. I
apologize for any inconvenience. I also have to find a
machine that has Access on it to be able to test, and
that also has a time limitation (like 5pm CT).

Anyway, I have been thinking about what you've said to
this point. It sounds as though I have to set up Date
Closed into another value, to be used later in
computation with the next Date Opened to produce MTBF
(Mean Time Between Failures). I have to brush up on my
SQL, too.

Let me get back with you, so that I can work on testing
and SQL. More later.
-----Original Message-----
Dear Calvin:

If you feel there are things we cannot accomplish in the newsgroup,
you may email me first. Please explain why you feel we need to speak
by phone. I can then reply with my phone if you have convinced me.

So you understand, most of us answering questions here are volunteers
who try to make a living as well. In the newsgroup, we can answer
questions as time permits, or ignore the questions when we're to busy.
So, we can get a tiny bit touchy about making deeper commitments.

I personally try to spread my limited time so I can help the largest
number of people. The newsgroups are the best venue for that, so
stick it out in here if you can.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


Thanks, Tom...Is there a phone number to reach you? I
know Access, but don't know SQL as well, but I'll give it
my best shot.

CALVIN
-----Original Message-----
Dear Calvin:

The problem of getting the value from the previous
record is a
separate one from what I addressed. To retrieve the
previous record
would require a correlated subquery.

In order to be able to do this, you must uniquely define
how to
retrieve the previous record, based on the data it
contains. By
uniquely I mean that, given your definition, there can
be at most one
row that meets that definition.

Let's work first on a query that can retrieve and
display this value
from the previous row. The rest is easy.

Please provide the SQL for a query that provides
everything except
this previous Date Closed. This query should be sorted
so the rows
are in the order that defines which is the previous row.

I'll try to take if from there and show how this can be
done.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Tue, 23 Mar 2004 22:57:57 -0800, "Calvin"

Thank you...My question is how to get the current
record's Date Opened, minus the previous record's Date
Closed?

"Datediff(excuse the syntax)[DateOpened] -
([DateClosed]-
1)"
to denote the previous record. The result goes on the
line of the current record.

Does this involve having to use Visual Basic, or SQL?
Also, this is a query, that will eventually be used in
a
report (summing the MTBF's and averaging them).

CALVIN
-----Original Message-----
Dear Calvin:

How about using Datediff to get the difference in
minutes, and divide
by 60, or in seconds and divide by 3600? Then you'd
have hours with a
decimal point. Taking the integer and fraction parts
of
this, you'd
have hours and fractions of an hour. Multiply the
fraction by 60 and
get minutes, with decimals again.

Should not be hard to do.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts

On Tue, 23 Mar 2004 22:08:03 -0800, "Calvin Shane"

My client is using Access to provide dates and times
on
equipment failures (using Date and Time opened as one
field, and date and time closed as one field (date
and
time separated by a space, in the following format:

Date closed field is mm/dd/yyyy hh:mm AM/PM
Date opened field is same as above.

Instead of using Excel (currently), he wants Access
to
produce Mean Time Between Failures (MTBF), which is
the
date/time closed of the next record, minus date/time
opened of the previous record (record -1), and
produce
result in the line of previous record, and so on.
MTBF
will not be produced for the 1st record, but will
thereafter. I've learned about using "Datediff", but
currently have no PC with Access to test it. With
these
formats, is it possible using "Datediff" to produce a
result in hours/minutes or hours.hundredth hours
(like
1.2 hours)?

.


.

.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 
T

Tom Ellison

Dear Calvin:

Obtaining a value from another row simultaneously depends on uniquely
describing that previous row and creating a subquery that retrieves
it. I don't see any hint of that in what you just posted.

This description of how to uniquely find the row that represents this
"previous record" is critical. I think you want the row whose Close
Date is the maximum of all Close Dates among those that precede the
row being considered. However, as you want to calculate MTBF, I
assume this must be chosen from among all the records for the same
object that may fail. I have to know how to describe "same object" as
well.

Be aware, once again, that the uniqueness of the "previous record"
must be guaranteed. It may be unique today, and the query will work.
But if you EVER have another failure recorded for the same object at
exactly the same time, the query will fail at that time, perhaps in
the future.

Probably, it is an error for a user to enter two failures for the same
object at the same time. You can constrain the database against this
eventuality with a unique index, preventing such duplication. This is
the best way to guarantee the query will avoid this unexpected
difficulty in the future. Otherwise, you may get bitten, and the
error message may be hard to understand.

"Subquery returns more than one row"

Or something like that.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 
C

Calvin Shane

Tom, I had to change thinking a little bit, based upon
what the client is looking for. I hope that this helps.

I've set up a sample small database, to include the
fields to be computed:

DateCreated DateClosed MTBF MTTR
10/7/99 10:24 AM 10/14/99 10:39 AM 168.25
10/14/99 1:44 PM 10/14/99 1:47 PM 0.05
10/15/99 7:06 AM 10/16/99 6:30 AM 23.40
10/16/99 7:14 AM 10/16/99 7:39 AM 0.43
10/17/99 6:37 AM 10/18/99 8:18 AM 25.68

The MTTR values were generated through the following SQL
(via Design view):

SELECT [TBL-AssetRecord].DateCreated, [TBL-
AssetRecord].DateClosed,
Datediff("n",[DateCreated],[DateClosed]/60 AS MTTR
FROM [TBL-AssetRecord]
GROUP BY [TBL-AssetRecord].DateCreated,[TBL-
AssetRecord].DateClosed
ORDER BY [TBL-AssetRecord].DateCreated

Was the above SQL query what you were asking for?

You're correct, and thank you, using minutes and dividing
by 60, will give x.xx in hours and hundredth hours (now,
I have to get it to 2 decimal places, but I think I can
figure that out). I did get MTTR to work on my new query.

For MTBF, the query is not comparing all of the
DateCreated or DateClosed fields, but actually taking one
column of data, subtracting DateClosed from DateCreated
to produce Mean Time To Repair (located on same line in
query). On the same query, was to be MTBF, however,
using record #2's DateCreated and subtracting record #1's
DateClosed, and so on. Therefore, Record #1 would not
have MTBF at all (based upon first failure at start of
day). Record #2's MTBF (in this example) would be 3
hours and 5 minutes, or 3.083 (repeating) hours.

Also, there will not be a time when DateCreated for a new
incident is earlier than the previous incident's
DateClosed...therefore, no negative times.

Am I heading in the right direction?

CALVIN



-----Original Message-----
Dear Calvin:

You said:

I have to set up Date Closed into another value, to be used later in
computation with the next Date Opened to produce MTBF (Mean Time
Between Failures)

I'm not sure what you mean, but that doesn't sound like what I tried
to express.

Depending on whether you can uniquely define which is the "previous
record" determines by the data it contains, you don't have to do
anything extraordinary. I can provide you with the query to do this.

Just post a query that returns everything you need other than the
value from the previous record. Make sure it is ordered uniquely so
that the row from which you want to extract the Date Closed is the one
just before the one where you have the Date Opened. I'll add the Date
Closed value to the query, then you can get to work calculating on it.



Thanks, Tom. This is my first time in a Newsgroup such
as this...I'm also getting into a time conflict, because
I want to get this problem solved soon for my client. I
apologize for any inconvenience. I also have to find a
machine that has Access on it to be able to test, and
that also has a time limitation (like 5pm CT).

Anyway, I have been thinking about what you've said to
this point. It sounds as though I have to set up Date
Closed into another value, to be used later in
computation with the next Date Opened to produce MTBF
(Mean Time Between Failures). I have to brush up on my
SQL, too.

Let me get back with you, so that I can work on testing
and SQL. More later.
-----Original Message-----
Dear Calvin:

If you feel there are things we cannot accomplish in
the
newsgroup,
you may email me first. Please explain why you feel
we
need to speak
by phone. I can then reply with my phone if you have convinced me.

So you understand, most of us answering questions here are volunteers
who try to make a living as well. In the newsgroup,
we
can answer
questions as time permits, or ignore the questions
when
we're to busy.
So, we can get a tiny bit touchy about making deeper commitments.

I personally try to spread my limited time so I can
help
the largest
number of people. The newsgroups are the best venue
for
that, so
stick it out in here if you can.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Wed, 24 Mar 2004 10:44:24 -0800, "Calvin Shane"

Thanks, Tom...Is there a phone number to reach you? I
know Access, but don't know SQL as well, but I'll
give
it
my best shot.

CALVIN
-----Original Message-----
Dear Calvin:

The problem of getting the value from the previous
record is a
separate one from what I addressed. To retrieve the
previous record
would require a correlated subquery.

In order to be able to do this, you must uniquely define
how to
retrieve the previous record, based on the data it
contains. By
uniquely I mean that, given your definition, there can
be at most one
row that meets that definition.

Let's work first on a query that can retrieve and
display this value
from the previous row. The rest is easy.

Please provide the SQL for a query that provides
everything except
this previous Date Closed. This query should be sorted
so the rows
are in the order that defines which is the previous row.

I'll try to take if from there and show how this can be
done.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Tue, 23 Mar 2004 22:57:57 -0800, "Calvin"

Thank you...My question is how to get the current
record's Date Opened, minus the previous record's Date
Closed?

"Datediff(excuse the syntax)[DateOpened] -
([DateClosed]-
1)"
to denote the previous record. The result goes on the
line of the current record.

Does this involve having to use Visual Basic, or SQL?
Also, this is a query, that will eventually be used in
a
report (summing the MTBF's and averaging them).

CALVIN
-----Original Message-----
Dear Calvin:

How about using Datediff to get the difference in
minutes, and divide
by 60, or in seconds and divide by 3600? Then you'd
have hours with a
decimal point. Taking the integer and fraction parts
of
this, you'd
have hours and fractions of an hour. Multiply the
fraction by 60 and
get minutes, with decimals again.

Should not be hard to do.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts

On Tue, 23 Mar 2004 22:08:03 -0800, "Calvin Shane"

My client is using Access to provide dates and times
on
equipment failures (using Date and Time opened as one
field, and date and time closed as one field (date
and
time separated by a space, in the following format:

Date closed field is mm/dd/yyyy hh:mm AM/PM
Date opened field is same as above.

Instead of using Excel (currently), he wants Access
to
produce Mean Time Between Failures (MTBF), which is
the
date/time closed of the next record, minus date/time
opened of the previous record (record -1), and
produce
result in the line of previous record, and so on.
MTBF
will not be produced for the 1st record, but will
thereafter. I've learned about using "Datediff", but
currently have no PC with Access to test it. With
these
formats, is it possible using "Datediff" to
produce
a
result in hours/minutes or hours.hundredth hours
(like
1.2 hours)?

.


.


.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
.
 
T

Tom Ellison

Dear Calvin:

SELECT DateCreated,
(SELECT MAX(DateClosed) FROM [TBL-AssetRecord] T1
WHERE T1.DateClosed < T.DateClosed) AS DateClosed
FROM [TBL-AssetRecord] T
ORDER BY DateCreated

If you save this query, you can then build your calculations on it,
right?

So, your table really only has one item in it for which you're
calculating MTBF?

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 
C

Calvin Shane

We're getting closer. MTBF is not getting the difference
from one DateClosed, but the previous DateClosed, so that
in my example:

DateCreated DateClosed MTBF MTTR
The difference betw. 1:44pm and 10:39am is 3hours, 5mins
(Thus 3.08 hours)
The difference betw. 7:06am (on 15th) and 1:47pm (on
14th) is 17hours 19mins (Thus 17.32 hours) and so on.

CALVIN
-----Original Message-----
Dear Calvin:

SELECT DateCreated,
(SELECT MAX(DateClosed) FROM [TBL-AssetRecord] T1
WHERE T1.DateClosed < T.DateClosed) AS DateClosed
FROM [TBL-AssetRecord] T
ORDER BY DateCreated

If you save this query, you can then build your calculations on it,
right?

So, your table really only has one item in it for which you're
calculating MTBF?

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


Tom, I had to change thinking a little bit, based upon
what the client is looking for. I hope that this helps.

I've set up a sample small database, to include the
fields to be computed:

DateCreated DateClosed MTBF MTTR
10/7/99 10:24 AM 10/14/99 10:39 AM 168.25
10/14/99 1:44 PM 10/14/99 1:47 PM 0.05
10/15/99 7:06 AM 10/16/99 6:30 AM 23.40
10/16/99 7:14 AM 10/16/99 7:39 AM 0.43
10/17/99 6:37 AM 10/18/99 8:18 AM 25.68

The MTTR values were generated through the following SQL
(via Design view):

SELECT [TBL-AssetRecord].DateCreated, [TBL-
AssetRecord].DateClosed,
Datediff("n",[DateCreated],[DateClosed]/60 AS MTTR
FROM [TBL-AssetRecord]
GROUP BY [TBL-AssetRecord].DateCreated,[TBL-
AssetRecord].DateClosed
ORDER BY [TBL-AssetRecord].DateCreated

Was the above SQL query what you were asking for?

You're correct, and thank you, using minutes and dividing
by 60, will give x.xx in hours and hundredth hours (now,
I have to get it to 2 decimal places, but I think I can
figure that out). I did get MTTR to work on my new query.

For MTBF, the query is not comparing all of the
DateCreated or DateClosed fields, but actually taking one
column of data, subtracting DateClosed from DateCreated
to produce Mean Time To Repair (located on same line in
query). On the same query, was to be MTBF, however,
using record #2's DateCreated and subtracting record #1's
DateClosed, and so on. Therefore, Record #1 would not
have MTBF at all (based upon first failure at start of
day). Record #2's MTBF (in this example) would be 3
hours and 5 minutes, or 3.083 (repeating) hours.

Also, there will not be a time when DateCreated for a new
incident is earlier than the previous incident's
DateClosed...therefore, no negative times.

Am I heading in the right direction?

CALVIN
.
 
T

Tom Ellison

Dear Calvin:

The query I sent is supposed to show the DateCreated with the previous
DateClosed. Isn't that what it is giving you? I was expecting:

DateCreated DateClosed
10/7/99 10:24 AM NULL
10/14/99 1:44 PM 10/14/99 10:39 AM
10/15/99 7:06 AM 10/14/99 1:47 PM
10/16/99 7:14 AM 10/16/99 6:30 AM
10/17/99 6:37 AM 10/16/99 7:39 AM

The DateClosed column should be the ones from the previous row. Based
on this query, you can calculate the MTBF. Right?

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 
C

Calvin Shane

I understand what you are saying, except that the
document I'd listed earlier is the way it appears in the
database. Therefore, DateClosed does start physically
with 10/14/99 10:39 AM. It is not Null. However, I see
what you are trying to do, I think. From what you're
listing, given the query, I should be able to produce the
MTBF.

Therefore, please correct me if I'm wrong...your previous
query can arrange things such that I can produce MTBF
(without changing the contents of either DateClosed and
DateCreated)...is that correct? Is it query that does
things behind the scenes?

Then, I can produce a query, such as:

SELECT [TBL-AssetRecord].DateCreated, [TBL-
AssetRecord].DateClosed,
Datediff("n",[DateCreated],[DateClosed]/60 AS MTBF
FROM [TBL-AssetRecord]
GROUP BY [TBL-AssetRecord].DateCreated,[TBL-
AssetRecord].DateClosed
ORDER BY [TBL-AssetRecord].DateCreated
CALVIN
-----Original Message-----
Dear Calvin:

The query I sent is supposed to show the DateCreated with the previous
DateClosed. Isn't that what it is giving you? I was expecting:

DateCreated DateClosed
10/7/99 10:24 AM NULL
10/14/99 1:44 PM 10/14/99 10:39 AM
10/15/99 7:06 AM 10/14/99 1:47 PM
10/16/99 7:14 AM 10/16/99 6:30 AM
10/17/99 6:37 AM 10/16/99 7:39 AM

The DateClosed column should be the ones from the previous row. Based
on this query, you can calculate the MTBF. Right?

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


We're getting closer. MTBF is not getting the difference
from one DateClosed, but the previous DateClosed, so that
in my example:

DateCreated DateClosed MTBF MTTR 25.68

The difference betw. 1:44pm and 10:39am is 3hours, 5mins
(Thus 3.08 hours)
The difference betw. 7:06am (on 15th) and 1:47pm (on
14th) is 17hours 19mins (Thus 17.32 hours) and so on.

CALVIN

.
 
T

Tom Ellison

Dear Calvin:

I'll try to be as clear as I can.

The query I gave you shows you the DateCreated from one row along with
the DateClosed from the previous row. It is on that basis you wanted
to calculate the MTBF, isn't it.

So, for the first row, there is no DateClosed from the previous row,
because there is no previous row. That's pretty much the definition
of "first" - the one before which there is no previous. So, compared
with your data, I have moved the DateClosed column DOWN one row. That
gives you the ability to calculate MTBF from one row of the query the
way it has been rearranged.

You could add the DateClosed from the same row to the query I
provided. Then, base your finished query on that query. You would
have the DateCreated, the DateClosed, and the PreviousDateClosed.
Isn't that everything you needed for MTBF and MTTR?

Don't overstrain. I'm thinking it should be easy for you to finish
this to your needs now.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


I understand what you are saying, except that the
document I'd listed earlier is the way it appears in the
database. Therefore, DateClosed does start physically
with 10/14/99 10:39 AM. It is not Null. However, I see
what you are trying to do, I think. From what you're
listing, given the query, I should be able to produce the
MTBF.

Therefore, please correct me if I'm wrong...your previous
query can arrange things such that I can produce MTBF
(without changing the contents of either DateClosed and
DateCreated)...is that correct? Is it query that does
things behind the scenes?

Then, I can produce a query, such as:

SELECT [TBL-AssetRecord].DateCreated, [TBL-
AssetRecord].DateClosed,
Datediff("n",[DateCreated],[DateClosed]/60 AS MTBF
FROM [TBL-AssetRecord]
GROUP BY [TBL-AssetRecord].DateCreated,[TBL-
AssetRecord].DateClosed
ORDER BY [TBL-AssetRecord].DateCreated
CALVIN
-----Original Message-----
Dear Calvin:

The query I sent is supposed to show the DateCreated with the previous
DateClosed. Isn't that what it is giving you? I was expecting:

DateCreated DateClosed
10/7/99 10:24 AM NULL
10/14/99 1:44 PM 10/14/99 10:39 AM
10/15/99 7:06 AM 10/14/99 1:47 PM
10/16/99 7:14 AM 10/16/99 6:30 AM
10/17/99 6:37 AM 10/16/99 7:39 AM

The DateClosed column should be the ones from the previous row. Based
on this query, you can calculate the MTBF. Right?

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


We're getting closer. MTBF is not getting the difference
from one DateClosed, but the previous DateClosed, so that
in my example:

DateCreated DateClosed MTBF MTTR
10/7/99 10:24 AM 10/14/99 10:39 AM n/a 168.25
10/14/99 1:44 PM 10/14/99 1:47 PM 3.08 0.05
10/15/99 7:06 AM 10/16/99 6:30 AM 17.32 23.40
10/16/99 7:14 AM 10/16/99 7:39 AM 0.73 0.43
10/17/99 6:37 AM 10/18/99 8:18 AM 22.97 25.68

The difference betw. 1:44pm and 10:39am is 3hours, 5mins
(Thus 3.08 hours)
The difference betw. 7:06am (on 15th) and 1:47pm (on
14th) is 17hours 19mins (Thus 17.32 hours) and so on.

CALVIN

.
 
C

Calvin Shane

I'll check that out and get back wtih you...Thanks again,
Tom. Any other thoughts from my previous message? I
hope that we're on the "same page".

CALVIN
-----Original Message-----
I understand what you are saying, except that the
document I'd listed earlier is the way it appears in the
database. Therefore, DateClosed does start physically
with 10/14/99 10:39 AM. It is not Null. However, I see
what you are trying to do, I think. From what you're
listing, given the query, I should be able to produce the
MTBF.

Therefore, please correct me if I'm wrong...your previous
query can arrange things such that I can produce MTBF
(without changing the contents of either DateClosed and
DateCreated)...is that correct? Is it query that does
things behind the scenes?

Then, I can produce a query, such as:

SELECT [TBL-AssetRecord].DateCreated, [TBL-
AssetRecord].DateClosed,
Datediff("n",[DateCreated],[DateClosed]/60 AS MTBF
FROM [TBL-AssetRecord]
GROUP BY [TBL-AssetRecord].DateCreated,[TBL-
AssetRecord].DateClosed
ORDER BY [TBL-AssetRecord].DateCreated
CALVIN
-----Original Message-----
Dear Calvin:

The query I sent is supposed to show the DateCreated with the previous
DateClosed. Isn't that what it is giving you? I was expecting:

DateCreated DateClosed
10/7/99 10:24 AM NULL
10/14/99 1:44 PM 10/14/99 10:39 AM
10/15/99 7:06 AM 10/14/99 1:47 PM
10/16/99 7:14 AM 10/16/99 6:30 AM
10/17/99 6:37 AM 10/16/99 7:39 AM

The DateClosed column should be the ones from the previous row. Based
on this query, you can calculate the MTBF. Right?

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


We're getting closer. MTBF is not getting the difference
from one DateClosed, but the previous DateClosed, so that
in my example:

DateCreated DateClosed MTBF MTTR
10/7/99 10:24 AM 10/14/99 10:39 AM n/a 168.25
10/14/99 1:44 PM 10/14/99 1:47 PM 3.08 0.05
10/15/99 7:06 AM 10/16/99 6:30 AM 17.32 23.40
10/16/99 7:14 AM 10/16/99 7:39 AM 0.73 0.43
10/17/99 6:37 AM 10/18/99 8:18 AM 22.97 25.68

The difference betw. 1:44pm and 10:39am is 3hours, 5mins
(Thus 3.08 hours)
The difference betw. 7:06am (on 15th) and 1:47pm (on
14th) is 17hours 19mins (Thus 17.32 hours) and so on.

CALVIN

.
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top