Separate Date/Time fields

  • Thread starter Christopher Caswell
  • Start date
C

Christopher Caswell

My user has insisted on having separate fields on my form for Date and Time,
when database design suggests there be one, in General Date format.

I assume the natural answer to this is to have two unbound fields, one in
Short Date format and one in Time format, and to split my database field up
and into the two text boxes "On Current", and to join the two values
together again on "Before Update".

What's the best way to go about doing this? I believe that dates are stored
as doubles, in "date.time" format, but can someone advise the best/most
efficient logic to unparse these values and then put them back together
again?
 
K

Ken Snell

Use the DateValue and TimeValue functions to extract the date and time
portions respectively from a date field's value.

DateInfo = DateValue([DateFieldName])

TimeInfo = TimeValue([DateFieldName])
 
D

Dale Fye

When my users insist on this functionality, I but three text boxes on
the form txtDateTime which is bound and hidden; and txtDate and
txtTime, which are unbound and visible. You can set the values for
txtDate and txtTime text boxes using the DateValue() and TimeValue()
functions to parse the DateTime field into the appropriate parts.

In the before update event of these two boxes, check to make sure that
there is something entered in the text box (I usually require a date,
but allow the time to be blank and set a blank time equal to
00:00:00). Then check to make sure the value entered is a valid date
or time using the IsDate() function (which returns True if the
parameter can be converted to a date). If it is, then concatenate the
value from txtDate and txtTime to fillin txtDateTime: me.txtDateTime =
Cdate(me.txtDate) + CDate(NZ(me.txtTime, "00:00:00"))


--
HTH

Dale Fye


My user has insisted on having separate fields on my form for Date and
Time,
when database design suggests there be one, in General Date format.

I assume the natural answer to this is to have two unbound fields, one
in
Short Date format and one in Time format, and to split my database
field up
and into the two text boxes "On Current", and to join the two values
together again on "Before Update".

What's the best way to go about doing this? I believe that dates are
stored
as doubles, in "date.time" format, but can someone advise the
best/most
efficient logic to unparse these values and then put them back
together
again?
 

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