How to add time to date?

J

Jeff

Hi ,

I have two textboxes to let user key in birthdate & birthtime separately.
The format of birthdate is yyyy/mm/dd and birthtime is AM 10:30 for example.
How can I combine birthdate and birthtime together as Date type? Thank you.
 
D

David H

Use DateValue and TimeValue to convert the values to a Date and Time
respectively and then sum them.

However, sound database design would dictate that you use one field to
capture the exact time as in [10/31/2009 07:52].
 
D

David H

Use DateValue() and TimeValue() to convert the values to the Date/Time values
and then sum them together as in ?DateValue("10/31/09") + TimeValue("7:39
AM").

However, sound database design would argue that both values should be
entered as a single value and saved as such as in

Birth Date/Time
[10/31/09 7:39 AM]

Using an InputMask and Format to capture the information and display it.
 
J

Jeff

Hi David,
Thank you very much for your quick response. It works perfectly.
--
Jeff


"David H" 來函:
Use DateValue() and TimeValue() to convert the values to the Date/Time values
and then sum them together as in ?DateValue("10/31/09") + TimeValue("7:39
AM").

However, sound database design would argue that both values should be
entered as a single value and saved as such as in

Birth Date/Time
[10/31/09 7:39 AM]

Using an InputMask and Format to capture the information and display it.

Jeff said:
Hi ,

I have two textboxes to let user key in birthdate & birthtime separately.
The format of birthdate is yyyy/mm/dd and birthtime is AM 10:30 for example.
How can I combine birthdate and birthtime together as Date type? Thank you.
 
M

Marshall Barton

Jeff said:
I have two textboxes to let user key in birthdate & birthtime separately.
The format of birthdate is yyyy/mm/dd and birthtime is AM 10:30 for example.
How can I combine birthdate and birthtime together as Date type?


Where do you want to put the result?

The base calculation can be done using the expression:
datetextbox + timetextbox
but I propose that using a single text box would be better.
 
F

fredg

Hi ,

I have two textboxes to let user key in birthdate & birthtime separately.
The format of birthdate is yyyy/mm/dd and birthtime is AM 10:30 for example.
How can I combine birthdate and birthtime together as Date type? Thank you.

As Access stores the values as numbers (the Format is irrelevant),
just add them together.
The date portion is the count of the number of days passed since
12/30/1899.
The Time portion is the decimal part of a 24 hour period,
So today is stored as 40008.0
The time (let's say it's 6:00 AM exactly) is stored as 0.25 (a quarter
of a 24 hour day).
So 40008.0 + 0.25 equals 40008.25 (or 7/14/2009 06:00:00)


=[BirthDate] + [BirthTime]

If you are storing the above 2 fields, this combined value ought NOT
be stored in a table. Simply recalculate it when needed.
If the 2 separate text boxes are just for the convenience of user
entry, then the table should have just one [DateOfBirth] field, and
you can use the Form's AfterUpdate event to store the combined values
into the one field:

Me.[DateOfBirth] = Me.[BirthDate] + [BirthTime]

You would use the Form's BeforeUpdate event to check whether both text
boxes have been filled (correctly).
 

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