473,416 Members | 1,729 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 102298
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.