Date & Time A97

K

Kahuna

Hi Folks

This seems like it should be simple - so perhaps I have my STOOPID head on
today or something!

I am writing a login app and I need to record the date AND time the user
logged in. Sounds simple enough:

tblLoggedIn![li_date_time] (General Date Format)

In the table view the record shows only the date - but no time?

My target is to use a form with something like the following:

...."Where DatePart("n",[li_date_time]) > DatePart("n",Now())-2"

Saying: where the last logged in time was longer than 2 mins ago!

Even just using DatePart("n",[li_date_time]) simply results in an ambiguous
number.

Have I got this completely wrong? How do I set the field to reference both
date and time together?

Help appreciated.
 
R

Rick Brandt

Kahuna said:
Hi Folks

This seems like it should be simple - so perhaps I have my STOOPID
head on today or something!

I am writing a login app and I need to record the date AND time the
user logged in. Sounds simple enough:

tblLoggedIn![li_date_time] (General Date Format)

In the table view the record shows only the date - but no time?

My target is to use a form with something like the following:

..."Where DatePart("n",[li_date_time]) > DatePart("n",Now())-2"

Saying: where the last logged in time was longer than 2 mins ago!

Even just using DatePart("n",[li_date_time]) simply results in an
ambiguous number.

Have I got this completely wrong? How do I set the field to reference
both date and time together?

Help appreciated.

You don't say how you are populating the field. Are you setting it in code
using the Now() function? Is the user entering the value manually? If the
latter are they entering a time? Entering a date only will not default to the
current time. It will default to midnight which (by default) Access does not
display.
 
J

John Spencer

Use the DateAdd function in your where clause

WHERE li_date_time > DateAdd("s",-120, Now())

Since we don't know how you are populating li_date_time , it is hard to
advise you why the time is not showing.
If you are using the Date() function that only gives the system date (time
as midnight). IF you use Now() that gives both date and time.
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Rick Brandt said:
Kahuna said:
Hi Folks

This seems like it should be simple - so perhaps I have my STOOPID
head on today or something!

I am writing a login app and I need to record the date AND time the
user logged in. Sounds simple enough:

tblLoggedIn![li_date_time] (General Date Format)

In the table view the record shows only the date - but no time?

My target is to use a form with something like the following:

..."Where DatePart("n",[li_date_time]) > DatePart("n",Now())-2"

Saying: where the last logged in time was longer than 2 mins ago!

Even just using DatePart("n",[li_date_time]) simply results in an
ambiguous number.

Have I got this completely wrong? How do I set the field to reference
both date and time together?

Help appreciated.

You don't say how you are populating the field. Are you setting it in
code using the Now() function? Is the user entering the value manually?
If the latter are they entering a time? Entering a date only will not
default to the current time. It will default to midnight which (by
default) Access does not display.
 
K

Kahuna

Rick Brandt said:
Kahuna said:
Hi Folks

This seems like it should be simple - so perhaps I have my STOOPID
head on today or something!

I am writing a login app and I need to record the date AND time the
user logged in. Sounds simple enough:

tblLoggedIn![li_date_time] (General Date Format)

In the table view the record shows only the date - but no time?

My target is to use a form with something like the following:

..."Where DatePart("n",[li_date_time]) > DatePart("n",Now())-2"

Saying: where the last logged in time was longer than 2 mins ago!

Even just using DatePart("n",[li_date_time]) simply results in an
ambiguous number.

Have I got this completely wrong? How do I set the field to reference
both date and time together?

Help appreciated.

You don't say how you are populating the field. Are you setting it in
code using the Now() function? Is the user entering the value manually?
If the latter are they entering a time? Entering a date only will not
default to the current time. It will default to midnight which (by
default) Access does not display.

Thanks Rick - that answers my question - I was having the field populated by
hand as a test - using the Now() function does populate it accurately.

AND

I found using the DateDiff() function instead of the DatePart() I was able
to determine the duration accurately too.

Brilliant Cheers Bud.
 

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