473,725 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 102560
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.TimeF ield = ([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 , stringThatSpeci fiesDesiredForm at)

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

Format(strDateT ime, "Long Time")
Format(strDateT ime, "Medium Time")
Format(strDateT ime, "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.r ogers.com> wrote in message
news:8Z******** ************@ro gers.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.r ogers.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.r ogers.com> wrote in
news:8Z******** ************@ro gers.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
14002
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 = 1234.56; $decimal = ($num - int($num)); print $decimal;
1
2253
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
1520
by: Sean | last post by:
How do I setup the DataGridTextBoxColumn object so that a DateTime variable only shows the time portion?
4
12907
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
1836
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 value. Looks like comparison of Time portion in query failed. I would appreciate any advice Thanks, Roman
3
5318
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 portion of the field defaults to 12:00am. What I want is to also store the time in the same datetime field as the date, but I want to use a separate control from the calendar control. I.e. I want the user to choose the date from the calendar control,...
6
2586
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 want 10:00:00 cmp with 9:00:00 so ddate1>ddate2 is true. I tried converting to short time string but the comparison can not be done on the strings. Thanks Paul. --
0
16498
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 formatting considerations at all. They are simple, easy, and brief and you should use them any time you need to incorporate any date literals or date math in your T-SQL code. create function DateOnly(@DateTime DateTime) -- Returns @DateTime...
0
2113
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 openTime = Convert.ToDateTime("9:30:00"); if (now < openTime)
0
8874
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8748
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9393
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9164
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9092
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8072
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4506
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4775
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2151
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.