473,383 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to combine date and time in the database

Hi,

I'm new to access and am very wary of dates as I have limited
experience in their manipulation and I know if they're not done
properly things can turn ugly quickly.

I would like to use a calendar control to allow my users to enter a
date but I need them to enter a time as well. It doesn't look like the
calendar control will allow times to be entered so I was thinking of
having two text boxes. One text box would contain the date they enter
and would be linked to a calendar control. The second text box would be
of type short time and would allow the user to enter time. I also
thought I would have a hidden date/time field. It would be populated
by code I would run in the onChange events of the first two text boxes
and it would be bound to the date/time database field.

So to my questions:
Is this the simplest way of implementing date/time entry?
What function should I use to combine the date and time in the hidden
field?

I'm not sure if what I've suggested is completely ridiculous or not.
Any help would be gratefully received.

Thanks

MM

Aug 18 '06 #1
6 12504
"Luvin lunch" <ma************@o2.iewrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
Hi,

I'm new to access and am very wary of dates as I have limited
experience in their manipulation and I know if they're not done
properly things can turn ugly quickly.

I would like to use a calendar control to allow my users to enter a
date but I need them to enter a time as well. It doesn't look like the
calendar control will allow times to be entered so I was thinking of
having two text boxes. One text box would contain the date they enter
and would be linked to a calendar control. The second text box would be
of type short time and would allow the user to enter time. I also
thought I would have a hidden date/time field. It would be populated
by code I would run in the onChange events of the first two text boxes
and it would be bound to the date/time database field.

So to my questions:
Is this the simplest way of implementing date/time entry?
What function should I use to combine the date and time in the hidden
field?

I'm not sure if what I've suggested is completely ridiculous or not.
Not at all ridiculous. I've never used a calendar control but I would
imagine that, if the bound control's format is "General Date" then it would
take the time element from the system clock, but even if it doesn't you can
use the "Time()" function to return the system time.

You can also use the "Time()" function to populate your (hidden) text box
with the system time in the form's Before Update event:

Me.txtMyTextBox = Time

remembering, of course, that it will be updated every time the current
record is updated.

HTH - Keith.
www.keithwilby.com
Aug 18 '06 #2
Hi Keith,

Thanks for the suggestions below.

What I need to do is allow the user to enter a time and a date
themselves. I'm setting up a kind of reminder system so that the user
is reminded at a certain date and time in the future to ring certain
people. The user therefore will be entering a date and time. I can't
use the system time.

Once the date and time is saved, I will display a list of the calls the
user has to make ordered by the call date and time. Because I'm
ordering by date and time I want to keep the date and time in one field
so I'm wondering how can I combine the date inputted and the time
inputted so that it's stored in only one field in access. Is this even
possible?

Thanks again

MM
Keith Wilby wrote:
"Luvin lunch" <ma************@o2.iewrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
Hi,

I'm new to access and am very wary of dates as I have limited
experience in their manipulation and I know if they're not done
properly things can turn ugly quickly.

I would like to use a calendar control to allow my users to enter a
date but I need them to enter a time as well. It doesn't look like the
calendar control will allow times to be entered so I was thinking of
having two text boxes. One text box would contain the date they enter
and would be linked to a calendar control. The second text box would be
of type short time and would allow the user to enter time. I also
thought I would have a hidden date/time field. It would be populated
by code I would run in the onChange events of the first two text boxes
and it would be bound to the date/time database field.

So to my questions:
Is this the simplest way of implementing date/time entry?
What function should I use to combine the date and time in the hidden
field?

I'm not sure if what I've suggested is completely ridiculous or not.

Not at all ridiculous. I've never used a calendar control but I would
imagine that, if the bound control's format is "General Date" then it would
take the time element from the system clock, but even if it doesn't you can
use the "Time()" function to return the system time.

You can also use the "Time()" function to populate your (hidden) text box
with the system time in the form's Before Update event:

Me.txtMyTextBox = Time

remembering, of course, that it will be updated every time the current
record is updated.

HTH - Keith.
www.keithwilby.com
Aug 18 '06 #3
Luvin lunch wrote:
Hi Keith,

Thanks for the suggestions below.

What I need to do is allow the user to enter a time and a date
themselves. I'm setting up a kind of reminder system so that the user
is reminded at a certain date and time in the future to ring certain
people. The user therefore will be entering a date and time. I can't
use the system time.

Once the date and time is saved, I will display a list of the calls the
user has to make ordered by the call date and time. Because I'm
ordering by date and time I want to keep the date and time in one field
so I'm wondering how can I combine the date inputted and the time
inputted so that it's stored in only one field in access. Is this even
possible?

Thanks again

MM
Keith Wilby wrote:
"Luvin lunch" <ma************@o2.iewrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
Hi,
>
I'm new to access and am very wary of dates as I have limited
experience in their manipulation and I know if they're not done
properly things can turn ugly quickly.
>
I would like to use a calendar control to allow my users to enter a
date but I need them to enter a time as well. It doesn't look like the
calendar control will allow times to be entered so I was thinking of
having two text boxes. One text box would contain the date they enter
and would be linked to a calendar control. The second text box would be
of type short time and would allow the user to enter time. I also
thought I would have a hidden date/time field. It would be populated
by code I would run in the onChange events of the first two text boxes
and it would be bound to the date/time database field.
>
So to my questions:
Is this the simplest way of implementing date/time entry?
What function should I use to combine the date and time in the hidden
field?
>
I'm not sure if what I've suggested is completely ridiculous or not.
Not at all ridiculous. I've never used a calendar control but I would
imagine that, if the bound control's format is "General Date" then it would
take the time element from the system clock, but even if it doesn't you can
use the "Time()" function to return the system time.

You can also use the "Time()" function to populate your (hidden) text box
with the system time in the form's Before Update event:

Me.txtMyTextBox = Time

remembering, of course, that it will be updated every time the current
record is updated.

HTH - Keith.
www.keithwilby.com
It is my opinion that Microsoft should have created a built-in function
for adding two date values or parts of date values. Although the
probability that the underlying data type for Date/Time will ever
change is absurdly low, simply adding date values together relies on
the way dates are implemented. It is more robust to use date functions
to perform this. That way, if the way dates are stored internally is
changed, the built-in date function can be changed by Microsoft and
nothing will break. The downside of this is that nearly any function
you roll on your own will be more complex than performing the addition.
A reasonable compromise might be to have a tiny wrapper function that
uses addition internally with the realization that the wrapper function
must change if the date storage mechanism changes. Another option is
to perform an unwieldy addition using the DateAdd function. Doing it
this way will not require changes later.

E.g.,

Wrapper function:

Public Function AddDates(dt1 As Date, dt2 As Date) As Date
AddDates = dt1 + dt2
End Function

DateAdd method:

Public Function AddDates(dt1 As Date, dt2 As Date) As Date
Dim dtDayPart As Date
Dim intSeconds As Integer

dtDayPart = DateAdd("s", -DatePart("s", dt1), dt1) + DateAdd("s",
-DatePart("s", dt2), dt2)
intSeconds = DatePart("s", dt1) + DatePart("s", dt2)
AddDates = DateAdd("s", intSeconds, dtDayPart)
End Function

Note that I avoided using Int(dt1) and Int(dt2). Still, none of these
implementations, especially direct addition without a wrapper, leave me
satisfied. IMO, Microsoft should have maintained this interface. I
think it was a question of sacrificing good practice for ease of use
in, say, query criteria. You asked a very good question.

James A. Fortune
CD********@FortuneJames.com

Aug 18 '06 #4
Per
You should be able to define the data source of the hidden date/time
field as the visible date field + the visible time field. Working with
dates and times is actually just like working with numbers; the date
part of a date/time field is just an integer (number of days since a
specific start date), while the time portion is the fraction, ie
fraction of a 24-hour day.

Here's an example:
Control Source: =[DocumentDate]+[DocumentTime]

If you want to make sure you don't get a time part from the date field
or a date part from the time field, you would have to use DateSerial
and TimeSerial:

Control Source:
=DateSerial(Year([DocumentDate]),Month([DocumentDate]),Day([DocumentDate])+TimeSerial(Hour([DocumentTime]),Minute([DocumentTime]),Second([DocumentTime]))

Also, if you're not sure that the date or time fields have non-null
values in them, you should use the Nz() function:

Control Source:
=DateSerial(Year(nz([DocumentDate],0)),Month(nz([DocumentDate]),0),Day(nz([DocumentDate],0))+TimeSerial(nz(Hour([DocumentTime],0)),Minute(nz([DocumentTime],0)),Second(nz([DocumentTime],0)))

Hope that works.

/Per

Luvin lunch wrote:
Hi Keith,

Thanks for the suggestions below.

What I need to do is allow the user to enter a time and a date
themselves. I'm setting up a kind of reminder system so that the user
is reminded at a certain date and time in the future to ring certain
people. The user therefore will be entering a date and time. I can't
use the system time.

Once the date and time is saved, I will display a list of the calls the
user has to make ordered by the call date and time. Because I'm
ordering by date and time I want to keep the date and time in one field
so I'm wondering how can I combine the date inputted and the time
inputted so that it's stored in only one field in access. Is this even
possible?

Thanks again

MM
Keith Wilby wrote:
"Luvin lunch" <ma************@o2.iewrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
Hi,
>
I'm new to access and am very wary of dates as I have limited
experience in their manipulation and I know if they're not done
properly things can turn ugly quickly.
>
I would like to use a calendar control to allow my users to enter a
date but I need them to enter a time as well. It doesn't look like the
calendar control will allow times to be entered so I was thinking of
having two text boxes. One text box would contain the date they enter
and would be linked to a calendar control. The second text box would be
of type short time and would allow the user to enter time. I also
thought I would have a hidden date/time field. It would be populated
by code I would run in the onChange events of the first two text boxes
and it would be bound to the date/time database field.
>
So to my questions:
Is this the simplest way of implementing date/time entry?
What function should I use to combine the date and time in the hidden
field?
>
I'm not sure if what I've suggested is completely ridiculous or not.
Not at all ridiculous. I've never used a calendar control but I would
imagine that, if the bound control's format is "General Date" then it would
take the time element from the system clock, but even if it doesn't you can
use the "Time()" function to return the system time.

You can also use the "Time()" function to populate your (hidden) text box
with the system time in the form's Before Update event:

Me.txtMyTextBox = Time

remembering, of course, that it will be updated every time the current
record is updated.

HTH - Keith.
www.keithwilby.com
Aug 18 '06 #5

Per wrote:
You should be able to define the data source of the hidden date/time
field as the visible date field + the visible time field. Working with
dates and times is actually just like working with numbers; the date
part of a date/time field is just an integer (number of days since a
specific start date), while the time portion is the fraction, ie
fraction of a 24-hour day.

Here's an example:
Control Source: =[DocumentDate]+[DocumentTime]

If you want to make sure you don't get a time part from the date field
or a date part from the time field, you would have to use DateSerial
and TimeSerial:

Control Source:
=DateSerial(Year([DocumentDate]),Month([DocumentDate]),Day([DocumentDate])+TimeSerial(Hour([DocumentTime]),Minute([DocumentTime]),Second([DocumentTime]))

Also, if you're not sure that the date or time fields have non-null
values in them, you should use the Nz() function:

Control Source:
=DateSerial(Year(nz([DocumentDate],0)),Month(nz([DocumentDate]),0),Day(nz([DocumentDate],0))+TimeSerial(nz(Hour([DocumentTime],0)),Minute(nz([DocumentTime],0)),Second(nz([DocumentTime],0)))

Hope that works.

/Per

Luvin lunch wrote:
Hi Keith,

Thanks for the suggestions below.

What I need to do is allow the user to enter a time and a date
themselves. I'm setting up a kind of reminder system so that the user
is reminded at a certain date and time in the future to ring certain
people. The user therefore will be entering a date and time. I can't
use the system time.

Once the date and time is saved, I will display a list of the calls the
user has to make ordered by the call date and time. Because I'm
ordering by date and time I want to keep the date and time in one field
so I'm wondering how can I combine the date inputted and the time
inputted so that it's stored in only one field in access. Is this even
possible?

Thanks again

MM
Keith Wilby wrote:
"Luvin lunch" <ma************@o2.iewrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
Hi,

I'm new to access and am very wary of dates as I have limited
experience in their manipulation and I know if they're not done
properly things can turn ugly quickly.

I would like to use a calendar control to allow my users to enter a
date but I need them to enter a time as well. It doesn't look like the
calendar control will allow times to be entered so I was thinking of
having two text boxes. One text box would contain the date they enter
and would be linked to a calendar control. The second text box would be
of type short time and would allow the user to enter time. I also
thought I would have a hidden date/time field. It would be populated
by code I would run in the onChange events of the first two text boxes
and it would be bound to the date/time database field.

So to my questions:
Is this the simplest way of implementing date/time entry?
What function should I use to combine the date and time in the hidden
field?

I'm not sure if what I've suggested is completely ridiculous or not.
>
Not at all ridiculous. I've never used a calendar control but I would
imagine that, if the bound control's format is "General Date" then it would
take the time element from the system clock, but even if it doesn't you can
use the "Time()" function to return the system time.
>
You can also use the "Time()" function to populate your (hidden) text box
with the system time in the form's Before Update event:
>
Me.txtMyTextBox = Time
>
remembering, of course, that it will be updated every time the current
record is updated.
>
HTH - Keith.
www.keithwilby.com
Aug 21 '06 #6
What I tried to say yesterday but it didn't work out was thanks for the
information. It's exactly what I was looking for.

MM

Luvin lunch wrote:
Per wrote:
You should be able to define the data source of the hidden date/time
field as the visible date field + the visible time field. Working with
dates and times is actually just like working with numbers; the date
part of a date/time field is just an integer (number of days since a
specific start date), while the time portion is the fraction, ie
fraction of a 24-hour day.

Here's an example:
Control Source: =[DocumentDate]+[DocumentTime]

If you want to make sure you don't get a time part from the date field
or a date part from the time field, you would have to use DateSerial
and TimeSerial:

Control Source:
=DateSerial(Year([DocumentDate]),Month([DocumentDate]),Day([DocumentDate])+TimeSerial(Hour([DocumentTime]),Minute([DocumentTime]),Second([DocumentTime]))

Also, if you're not sure that the date or time fields have non-null
values in them, you should use the Nz() function:

Control Source:
=DateSerial(Year(nz([DocumentDate],0)),Month(nz([DocumentDate]),0),Day(nz([DocumentDate],0))+TimeSerial(nz(Hour([DocumentTime],0)),Minute(nz([DocumentTime],0)),Second(nz([DocumentTime],0)))

Hope that works.

/Per

Luvin lunch wrote:
Hi Keith,
>
Thanks for the suggestions below.
>
What I need to do is allow the user to enter a time and a date
themselves. I'm setting up a kind of reminder system so that the user
is reminded at a certain date and time in the future to ring certain
people. The user therefore will be entering a date and time. I can't
use the system time.
>
Once the date and time is saved, I will display a list of the calls the
user has to make ordered by the call date and time. Because I'm
ordering by date and time I want to keep the date and time in one field
so I'm wondering how can I combine the date inputted and the time
inputted so that it's stored in only one field in access. Is this even
possible?
>
Thanks again
>
MM
>
>
Keith Wilby wrote:
"Luvin lunch" <ma************@o2.iewrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
Hi,
>
I'm new to access and am very wary of dates as I have limited
experience in their manipulation and I know if they're not done
properly things can turn ugly quickly.
>
I would like to use a calendar control to allow my users to enter a
date but I need them to enter a time as well. It doesn't look like the
calendar control will allow times to be entered so I was thinking of
having two text boxes. One text box would contain the date they enter
and would be linked to a calendar control. The second text box would be
of type short time and would allow the user to enter time. I also
thought I would have a hidden date/time field. It would be populated
by code I would run in the onChange events of the first two text boxes
and it would be bound to the date/time database field.
>
So to my questions:
Is this the simplest way of implementing date/time entry?
What function should I use to combine the date and time in the hidden
field?
>
I'm not sure if what I've suggested is completely ridiculous or not.

Not at all ridiculous. I've never used a calendar control but I would
imagine that, if the bound control's format is "General Date" then it would
take the time element from the system clock, but even if it doesn't you can
use the "Time()" function to return the system time.

You can also use the "Time()" function to populate your (hidden) text box
with the system time in the form's Before Update event:

Me.txtMyTextBox = Time

remembering, of course, that it will be updated every time the current
record is updated.

HTH - Keith.
www.keithwilby.com
Aug 22 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Steve Jorgensen | last post by:
Hi all, I'm working on the schema for a database that must represent data about stock & bond funds over time. My connundrum is that, for any of several dimension fields, including the fund name...
3
by: Nick | last post by:
I am working a new application...well actually a series of applications for my company. They want internal users to be able to go to a site and everything regarding security is transparent,...
5
by: Jamie Pittman via AccessMonster.com | last post by:
I have two tables with 5000 entries on them. One is based for regular time with several variables example (employee name, date,time in and out, code, customer, building) I have another table that...
1
by: mojo | last post by:
We have set up an Access database with tables x,y, & z where we would like to have multiple people entering data into a table x. Each person has an identical copy of the database on their PC's. ...
5
by: jhutchings | last post by:
Hello everyone, I have a database where I collect shipment data from various tables. However, I have a problem. Whenever I want to see shipping data for orders that were set to ship on or before...
2
by: drurjen | last post by:
Good morning. I am importing an XLS file into one of my tables. The fields are: Date Id Time IO 12/22/2006 2 12:48:45 PM 9 12/22/2006 16 5:40:55 AM 1 12/22/2006 16 12:03:59 PM 2 ...
1
by: csolomon | last post by:
Hello: I am using two queries to get one result set. The issue is, I return no data when I combine them into one query. I have listed both queries, as well as the 3rd query that shows them...
4
by: ghjk | last post by:
In my php application user should enter date and time separately. But i want to combine them to compare with database value. How can i do that? user input Date:2008-03-25 User input time:11:30 Eg;...
8
by: ghjk | last post by:
In my php application I got the date and time as two separate values.(User entered value) ex:date =06-07-2008 time =16:10 I want to combine those two values and convert the date format like the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.