A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

max of date/time



 
 
Thread Tools Display Modes
  #1  
Old October 30th, 2008, 05:48 PM posted to microsoft.public.access
dchristo
external usenet poster
 
Posts: 35
Default max of date/time

I am trying to get the last record, example

Item # date time comment

125 10/28/2008 15:39 sent instructions
125 10/28/2008 16:43 cancelled instructions
125 03/05/2008 09:23 sent instructions
125 03/05/2008 10:45 cancelled instructions
125 11/28/2007 07:13 sent instructions

I only want the last record: ie 16:43 cancelled instructions

Any help would be appreciated.

Thank you
  #2  
Old October 30th, 2008, 06:00 PM posted to microsoft.public.access
Rick Brandt
external usenet poster
 
Posts: 4,354
Default max of date/time

dchristo wrote:
I am trying to get the last record, example

Item # date time comment

125 10/28/2008 15:39 sent instructions
125 10/28/2008 16:43 cancelled
instructions 125 03/05/2008 09:23 sent
instructions 125 03/05/2008 10:45
cancelled instructions 125 11/28/2007 07:13
sent instructions

I only want the last record: ie 16:43 cancelled instructions

Any help would be appreciated.


SELECT Top 1 TableName.*
FROM TableName
ORDER BY [date] DESC, [time] DESC

Additional comments:
As "date" and "time" are reserved words you should not use them for field
names.

Date and time are (usually) better stored in one field rather than split up
into two.


--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


  #3  
Old October 30th, 2008, 06:13 PM posted to microsoft.public.access
Ken Sheridan
external usenet poster
 
Posts: 3,433
Default max of date/time

I assume it’s the latest date/time per item number you want. With your
separate date and time columns you can include a correlated subquery in the
query's WHERE clause to return the latest date+time value:

SELECT *
FROM [YourTable] AS T1
WHERE [date]+[time] =
(SELECT MAX([date]+[time])
FROM YourTable as T2
WHERE T2.[Item #] = T1.[item #]);

If you want the latest date/time of all rows not per item number then omit
the correlation on the item # column form the subquery.

However you'd be better using a single column for the date and time. In
Access there is no such thing as a date value or time value per se, only a
date/time value. Your time column in fact is storing the time on 30 December
1899, which is day zero in Access's implementation of the date/time data
type, and your date column is storing the point of time at midnight at the
start of the day.

Also, date and time are best avoided as column names as these are the name
of built in functions.

Ken Sheridan
Stafford, England

"dchristo" wrote:

I am trying to get the last record, example

Item # date time comment

125 10/28/2008 15:39 sent instructions
125 10/28/2008 16:43 cancelled instructions
125 03/05/2008 09:23 sent instructions
125 03/05/2008 10:45 cancelled instructions
125 11/28/2007 07:13 sent instructions

I only want the last record: ie 16:43 cancelled instructions

Any help would be appreciated.

Thank you


  #4  
Old October 30th, 2008, 07:30 PM posted to microsoft.public.access
dchristo
external usenet poster
 
Posts: 35
Default max of date/time

Unfortunately, I do not have control of the fields they are named DATE_ENTER
and TIME_STAMP they come from tables pull from mainframe.



"Ken Sheridan" wrote:

I assume it’s the latest date/time per item number you want. With your
separate date and time columns you can include a correlated subquery in the
query's WHERE clause to return the latest date+time value:

SELECT *
FROM [YourTable] AS T1
WHERE [date]+[time] =
(SELECT MAX([date]+[time])
FROM YourTable as T2
WHERE T2.[Item #] = T1.[item #]);

If you want the latest date/time of all rows not per item number then omit
the correlation on the item # column form the subquery.

However you'd be better using a single column for the date and time. In
Access there is no such thing as a date value or time value per se, only a
date/time value. Your time column in fact is storing the time on 30 December
1899, which is day zero in Access's implementation of the date/time data
type, and your date column is storing the point of time at midnight at the
start of the day.

Also, date and time are best avoided as column names as these are the name
of built in functions.

Ken Sheridan
Stafford, England

"dchristo" wrote:

I am trying to get the last record, example

Item # date time comment

125 10/28/2008 15:39 sent instructions
125 10/28/2008 16:43 cancelled instructions
125 03/05/2008 09:23 sent instructions
125 03/05/2008 10:45 cancelled instructions
125 11/28/2007 07:13 sent instructions

I only want the last record: ie 16:43 cancelled instructions

Any help would be appreciated.

Thank you


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:10 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.