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

time from datetime

Is here an easy way to get 9:00 PM from 5/1/2005 9:00:00 PM without
doing:
Cast(DATEPART(HOUR,xDate) as varchar(2)) + ':' +
Cast(DATEPART(MINUTE,xDate) as varchar(2))
lq

Jul 23 '05 #1
3 1794
Declare @Dt DateTime
Set @Dt = '5/1/2005 9:00:00 PM'
Print Convert(nvarchar(20), @Dt, 108)

Jul 23 '05 #2
On 9 May 2005 09:04:05 -0700, laurenq uantrell wrote:
Is here an easy way to get 9:00 PM from 5/1/2005 9:00:00 PM without
doing:
Cast(DATEPART(HOUR,xDate) as varchar(2)) + ':' +
Cast(DATEPART(MINUTE,xDate) as varchar(2))
lq


Hi lq,

Check out the various style options described under CONVERT in Books
Online. Depending on the formatting required, you could use one of the
examples below, or change them to your needs:

SELECT CONVERT(char(12), CURRENT_TIMESTAMP, 114)
SELECT SUBSTRING(CONVERT(char(23), CURRENT_TIMESTAMP, 121), 12, 12)
SELECT SUBSTRING(CONVERT(char(19), CURRENT_TIMESTAMP, 100), 13, 7)
SELECT SUBSTRING(CONVERT(char(25), CURRENT_TIMESTAMP, 131), 12, 14)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #3
Of course!
I didn't consider the simple solution of trimming off the date portion
of a built-in time/date format. Too bad there's not an equivalent of
Convert...108 that yields hh:mm am/pm.
lq

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
4
by: Jan Danielsson | last post by:
Hello all, I have a list of servers which an application connects to. If the connection fails, the application should mark the server as temporarily unavailable, and should try to use the server...
16
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am...
3
by: Jon Davis | last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST" The problem: // this fails on PST DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST"); Help? Jon
2
by: DWalker | last post by:
In Visual Studio (Visual Basic) .NET 2002, I noticed that this: Dim Elapsed as DateTime = Now - Now gives a "compile time" error (error in the IDE), saying that the '-' operator is not...
4
by: Maziar Aflatoun | last post by:
Hi, Can someone please tell me how I can set DateTime to 01/01/1970 (UTC). Doing the following DateTime dt1 = new DateTime(1970, 1,1); Debug.WriteLine("dt1(utc):"+...
7
by: Dick | last post by:
I have a long list of events. I know where each event took place (globally) and when (using the event’s local time). I want to do some comparisons between these date/times. I thought I would...
9
by: Ron Adam | last post by:
I'm having some cross platform issues with timing loops. It seems time.time is better for some computers/platforms and time.clock others, but it's not always clear which, so I came up with the...
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...
25
by: Brian | last post by:
I have a datetimepicker formated for just time, the user selects the time. I want to compare if that time is between midnight and 8 am dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM# this...
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
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?
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:
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
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
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
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.