Connecting Tech Pros Worldwide Help | Site Map

Date/Time Calculation

Shaun Harwood
Guest
 
Posts: n/a
#1: May 6 '06
Hello all

I seem to be getting nowhere with this issue - I'm sure it is not that
complex so here goes. I want to create a table with three fields - two
date/time types (Start_Date & Stop_Date) into which I enter dates. The
third field is a calculated value of the days between Start and Stop.
I have tried using Datediff but for some reasson it doesn't like basing the
value of my calculated days field on the result of a query calculated from
withing the same table. Hope this makes sense.

If anybody has a solution I would be grateful - this fast becoming an
obsession! - I am using MS Access 2003 on a Win XP SP2 platform.

Best Regards

Shaun H
DFS
Guest
 
Posts: n/a
#2: May 6 '06

re: Date/Time Calculation


Shaun,

To get the # of days between the dates, you can write a simple update query:

UPDATE table
SET DaysBetween = StopDate - StartDate
WHERE StartDate IS NOT NULL
AND StopDate IS NOT NULL;

If your DaysBetween field is set to Single or Double precision, that query
will return fractions of a day.




Shaun Harwood wrote:[color=blue]
> Hello all
>
> I seem to be getting nowhere with this issue - I'm sure it is not that
> complex so here goes. I want to create a table with three fields -
> two date/time types (Start_Date & Stop_Date) into which I enter
> dates. The third field is a calculated value of the days between
> Start and Stop.
> I have tried using Datediff but for some reasson it doesn't like
> basing the value of my calculated days field on the result of a query
> calculated from withing the same table. Hope this makes sense.
>
> If anybody has a solution I would be grateful - this fast becoming an
> obsession! - I am using MS Access 2003 on a Win XP SP2 platform.
>
> Best Regards
>
> Shaun H[/color]


Shaun Harwood
Guest
 
Posts: n/a
#3: May 6 '06

re: Date/Time Calculation


Thankyou - that does the job perfectly - now is there a way to run the
update query automatically (maybe when you start access) so the field will
update itself - or do I have to run the query each time.

Thanks

[color=blue]
>
>
>[/color]

RoyVidar
Guest
 
Posts: n/a
#4: May 6 '06

re: Date/Time Calculation


Shaun Harwood wrote in message
<Xns97BB1111F2C39shaunharwoodsympatic@207.35.177.1 35> :[color=blue]
> Thankyou - that does the job perfectly - now is there a way to run
> the update query automatically (maybe when you start access) so the
> field will update itself - or do I have to run the query each time.
>
> Thanks
>
>[color=green]
>>
>>
>>[/color][/color]

I would recommend that you rethink this strategy. It is considered much
better to calculate values on the fly, when you need them, in stead of
storing the calculated values.

When choosing to "break the rules", as in storing calculated values,
you
expose yourself to the calculated risk of your updates failing,
creating
a situation where your calculated values are out of sync with the
fields
they are supposed to be derived from.

--
Roy-Vidar


Closed Thread