Merging Date and Time Fields in Access 2013 - Microsoft Community

Merging Date and Time Fields in Access 2013

Hi,

I'm new to Access, and have a Table concerning hospital care that includes separate fields for 'Admission Date' and 'Admission Time', 'Discharge Date' and 'Discharge Time' and a lot of other examples.

I'd like to combine the relevant pairs into one variable, so as to be able to calculate 'Length of Stay in Hospital' and similar time intervals. In retrospect, I wish they'd each been collected as a single General Date variable.

Is there a simple way to accomplish this? The internet hasn't helped me, thus far, and I'd really appreciate some guidance.

Thank you,

Tom

The date/time data type is simply a 64 bit floating point number under the skin, so all you have to do is add the values with [Admission Date]+[Admission Time] for instance.  While you can use the resulting value in calculations, you can easily create a new single column and insert the combined value into it with an 'update'query, e.g.

Update [YourTable]
SET [AdmissionDateTime] = [Admission Date]+[Admission Time]
[DischargeDateTime] = [Discharge Date]+[Discharge Time];

You can then remove the redundant columns from the table once you are staisfied that the results are correct.  But back-up the file first!

You might be interested in the file Timesheet.zip in my public databases folder at:

https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169

If you have difficulty opening the link copy its text (NB, not the link location) and paste it into your browser's address bar.

This little demo file includes a number of functions for doing date/time arithmetic where the result is 24 hours or more, which you cannot do directly by subtracting the date/time values.

_____________________
Ken Sheridan,
Newport, Shropshire, England

"Don't write it down until you understand it!" - Richard Feynman

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

While Ken's answer is correct, he is assuming that your 2 fields are Date/Time datatypes. If so, then do as he suggest. If not, we need to know what the datatypes for the 2 fields are.

Also if they are Date/Time types. I would suggest you run a query and format both fields as General Date. The date field should show the date with 00:00:00 as the time. The time field should show 12/30/1899 as the date. If these are not the case, then adding the two together will get inaccurate results. 

Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Microsoft Access MVP since 2007

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 1,134 Applies to: