PC Review


Reply
Thread Tools Rate Thread

How to add time to date?

 
 
Jeff
Guest
Posts: n/a
 
      14th Jul 2009
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.
--
Jeff
 
Reply With Quote
 
 
 
 
David H
Guest
Posts: n/a
 
      14th Jul 2009
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].

"Jeff" wrote:

> 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.
> --
> Jeff

 
Reply With Quote
 
David H
Guest
Posts: n/a
 
      14th Jul 2009
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" wrote:

> 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.
> --
> Jeff

 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      14th Jul 2009
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" wrote:
>
> > 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.
> > --
> > Jeff

 
Reply With Quote
 
Marshall Barton
Guest
Posts: n/a
 
      14th Jul 2009
Jeff wrote:
>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.

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
fredg
Guest
Posts: n/a
 
      14th Jul 2009
On Tue, 14 Jul 2009 06:00:01 -0700, Jeff wrote:

> 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).
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting text format of time/date into Excel time/date for subtr YY san. Microsoft Excel Worksheet Functions 5 25th Feb 2010 07:13 AM
Calculating days & time left from start date/time to end date/time =?Utf-8?B?bWFyaWU=?= Microsoft Excel Worksheet Functions 7 7th Dec 2005 02:36 PM
Date/Time datatype in Access 2003 affects date/time duplicate quer =?Utf-8?B?VGltIFQ=?= Microsoft Access Queries 4 27th Jun 2005 02:20 AM
Medium Time setting does not hide date from a date/time duplicateq =?Utf-8?B?VGltIFQ=?= Microsoft Access Getting Started 0 26th Jun 2005 08:49 PM
Calc. Length of time with time-in, time-out, date-in, date-out in diff. columns Niceven Microsoft Excel Misc 2 28th May 2004 04:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:37 AM.