By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,002 Members | 2,157 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,002 IT Pros & Developers. It's quick & easy.

How to extract just the time portion of DateTime

P: n/a
rs
I have a table with a timestamp field which contains the date and time. ie.
9/13/2004 9:10:00 AM.
I would like to split this field into 2 fields, one with just the DATE
portion ie 9/13/2004
and the other with just the TIME portion. ie 9:10:00 AM.

I can make the table view display what I want by placing the same data in 3
fields and setting the display property to 'General Date',' Medium Time' and
'Short Date' but the underlying data in all fields is the same.

As simple as it sounds I can not find a simple way to accomplish this
besides highlighting half the field and using cut&paste to populate the new
fields.

One solution I have tried is to run an Update query to Set the new fields to
the time or date portion.

I can set the new fields to just about any single date or time module but
nothing to extract just the time or date portion. It seems there are
functions to extract the Day, month, day, hour, minute, etc.. but not the
date or time portions of a date time field.

any ideas would be helpful
Thanks BOB
Dec 8 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Thu, 8 Dec 2005 13:42:47 -0330, rs wrote:
I have a table with a timestamp field which contains the date and time. ie.
9/13/2004 9:10:00 AM.
I would like to split this field into 2 fields, one with just the DATE
portion ie 9/13/2004
and the other with just the TIME portion. ie 9:10:00 AM.

I can make the table view display what I want by placing the same data in 3
fields and setting the display property to 'General Date',' Medium Time' and
'Short Date' but the underlying data in all fields is the same.

As simple as it sounds I can not find a simple way to accomplish this
besides highlighting half the field and using cut&paste to populate the new
fields.

One solution I have tried is to run an Update query to Set the new fields to
the time or date portion.

I can set the new fields to just about any single date or time module but
nothing to extract just the time or date portion. It seems there are
functions to extract the Day, month, day, hour, minute, etc.. but not the
date or time portions of a date time field.

any ideas would be helpful
Thanks BOB


[DateField] - Int([DateField])

Update YourTable Set YourTable.TimeField = ([DateField] -
Int([DateField]));
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Dec 8 '05 #2

P: n/a
You can use the Format() function to change the way your dates are
presented, or in an update query to change the dates in your tables to
look the way you want them to. If you want to present the dates the
same way in more than one form or report, I would suggest changing the
data in the tables themselves.

Syntax is:

Format(yourDate, stringThatSpecifiesDesiredFormat)

For example, if your timestamp is contained in strDateTime, you can do
this:
Format(strDateTime, "General Date")
Format(strDateTime, "Long Date")
Format(strDateTime, "Medium Date")
Format(strDateTime, "Short Date")

Format(strDateTime, "Long Time")
Format(strDateTime, "Medium Time")
Format(strDateTime, "Short Time")

You can find more information about manipulating dates and times in
this MSDN article ("Performing Simple Calculations"):
http://msdn.microsoft.com/library/de...lculations.asp

Dec 8 '05 #3

P: n/a
rs
THANKS !!
I've been on this for over a day..
soooooooo simple. subtract the integer from itself..

Reminds me of when a customer asked why he was charged $20 to change a 10
cent fuse?
The reply was.. 10 cents for the fuse and $19.90 for knowing which fuse!

Thanks again.

BOB

"rs" <re**********************@nl.rogers.com> wrote in message
news:8Z********************@rogers.com...
I have a table with a timestamp field which contains the date and time. ie. 9/13/2004 9:10:00 AM.
I would like to split this field into 2 fields, one with just the DATE
portion ie 9/13/2004
and the other with just the TIME portion. ie 9:10:00 AM.

I can make the table view display what I want by placing the same data in 3 fields and setting the display property to 'General Date',' Medium Time' and 'Short Date' but the underlying data in all fields is the same.

As simple as it sounds I can not find a simple way to accomplish this
besides highlighting half the field and using cut&paste to populate the new fields.

One solution I have tried is to run an Update query to Set the new fields to the time or date portion.

I can set the new fields to just about any single date or time module but
nothing to extract just the time or date portion. It seems there are
functions to extract the Day, month, day, hour, minute, etc.. but not the
date or time portions of a date time field.

any ideas would be helpful
Thanks BOB

Dec 8 '05 #4

P: n/a

See Access help on the "DateValue" and "TimeValue" functions.

DateValue(#9/13/2004 9:10:00 AM#) = 9/30/2004
TimeValue(#9/13/2004 9:10:00 AM#) = 9:10:00 AM

Avoid the Format and Format$ functions since these return strings, not
dates.

Personally, I'd just use the DateValue and TimeValue functions in
queries when exporting data, and not on the underlying tables to
create 2 columns, since regardless of what you would like *all*
date/time fields contain both the date and the time.

A "blank" or not displayed date will *always* be 12/30/1899, and a
time that isn't displayed is always going to be midnight.

When doing calculations or selections on/with date/time fields with
the date and time potions separated can cause unexpected results.

On Thu, 8 Dec 2005 13:42:47 -0330, "rs"
<re**********************@nl.rogers.com> wrote:
I have a table with a timestamp field which contains the date and time. ie.
9/13/2004 9:10:00 AM.
I would like to split this field into 2 fields, one with just the DATE
portion ie 9/13/2004
and the other with just the TIME portion. ie 9:10:00 AM.
I can make the table view display what I want by placing the same data in 3
fields and setting the display property to 'General Date',' Medium Time' and
'Short Date' but the underlying data in all fields is the same.
As simple as it sounds I can not find a simple way to accomplish this
besides highlighting half the field and using cut&paste to populate the new
fields.
One solution I have tried is to run an Update query to Set the new fields to
the time or date portion.
I can set the new fields to just about any single date or time module but
nothing to extract just the time or date portion. It seems there are
functions to extract the Day, month, day, hour, minute, etc.. but not the
date or time portions of a date time field.
any ideas would be helpful

--
Drive C: Error. (A)bort (R)etry (S)mack The Darned Thing

Dec 8 '05 #5

P: n/a
"rs" <re**********************@nl.rogers.com> wrote in
news:8Z********************@rogers.com:
I have a table with a timestamp field which contains the date
and time. ie. 9/13/2004 9:10:00 AM.
I would like to split this field into 2 fields, one with just
the DATE
portion ie 9/13/2004
and the other with just the TIME portion. ie 9:10:00 AM.

I can make the table view display what I want by placing the
same data in 3 fields and setting the display property to
'General Date',' Medium Time' and 'Short Date' but the
underlying data in all fields is the same.

As simple as it sounds I can not find a simple way to
accomplish this besides highlighting half the field and using
cut&paste to populate the new fields.

One solution I have tried is to run an Update query to Set the
new fields to the time or date portion.

I can set the new fields to just about any single date or time
module but nothing to extract just the time or date portion.
It seems there are functions to extract the Day, month, day,
hour, minute, etc.. but not the date or time portions of a
date time field.

any ideas would be helpful
Thanks BOB

Some observations:
1) You should never allow any direct display or editing of a
table by a user.
2) Queries, forms and reports can have three textboxes pointing
to the same field and so display the desired data.
3) Since the date/time field will show a date in 1899 if
something happens to the formatting for the time-only box, you
may really confuse and frustrate the users when they try to
enter the time in the field, you should avoid using this
technique.
4) Calculating elapsed times using the separate fields is a
nightmare. With the single field it's a snap. .
--
Bob Quintal

PA is y I've altered my email address.
Dec 10 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.