473,416 Members | 1,868 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,416 software developers and data experts.

How to extract just the time portion of DateTime

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
5 102299
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
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
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

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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tharma | last post by:
Hi I wanted to extract the decimal portion from a number. I tried the following code but I didn't get the exact decimal portion. If anyone know how to extract please let me know. $num =...
1
by: Pooja Raisingani via AccessMonster.com | last post by:
Hello, Can anyone please tell me How to use a select query to extract date from a Datetime field in Access 2000?? Thanks -- Message posted via http://www.accessmonster.com
3
by: Sean | last post by:
How do I setup the DataGridTextBoxColumn object so that a DateTime variable only shows the time portion?
4
by: kashifsulemani | last post by:
we have a table like this OrderNo OrderDate 1 2005-11-04 01:12:47.000 2 2005-11-19 04:26:54.000 3 2005-11-16 11:03:23.000 4 2005-11-21 15:58:37.000 5 2005-11-24 21:45:04.000
3
by: muntyanu | last post by:
Hi all, I have datetime field in database. When I am getting records older than specific date that I passed in parameter I can not get records that differs only in Time part of the datetime...
3
by: john | last post by:
I am using MS Sql Express as the backend database for a Microsoft Access front end application. I am using a calendar control to store the desired date in the sql datetime field. The time...
6
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I am trying to compare just the time portion of two variables that are of date time part. For example I have dtdate1= 2/2/07 10:00:00 dtdate2=3/4/07 9:00:00 so for the comparision I would...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
0
by: Curious | last post by:
I have the code below. But it won't compile. //Compiling error: Cannot implicitly convert type 'System.TimeSpan' to 'System.DateTime' DateTime now = DateTime.Now.TimeOfDay; DateTime...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.