473,402 Members | 2,055 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,402 software developers and data experts.

simple way to convert '1900-01-01 17:12:00.000' to 5:12pm?

I have a table called class_time. and the column name is start_time.
datatype is datetime.

id start_time
2 1900-01-01 15:00:00.000
4 1900-01-01 17:12:00.000

i want to the convert the start_time column into a format that only
has the hour and minutes plus AM/PM ( for example, 3:00 pm, 5:12pm)

id start_time new format
2 1900-01-01 15:00:00.000 3:00 pm

is there any simple one step way to do that?

(the only way i know is to use the following query, then do a substring
where the space is. but that's too complicated)
select CONVERT(CHAR(20), start_time, 22) from class_time

Thank you in advance for your time.

Oct 25 '06 #1
2 1949
On 25 Oct 2006 10:41:21 -0700, ed********@hotmail.com wrote:
>I have a table called class_time. and the column name is start_time.
datatype is datetime.

id start_time
2 1900-01-01 15:00:00.000
4 1900-01-01 17:12:00.000

i want to the convert the start_time column into a format that only
has the hour and minutes plus AM/PM ( for example, 3:00 pm, 5:12pm)

id start_time new format
2 1900-01-01 15:00:00.000 3:00 pm

is there any simple one step way to do that?

(the only way i know is to use the following query, then do a substring
where the space is. but that's too complicated)
select CONVERT(CHAR(20), start_time, 22) from class_time

Thank you in advance for your time.
Hi eddiekwang,

Something like this?

SELECT STUFF(CONVERT(char(19), start_time, 100), 1, 12, '')
FROM class_time;

--
Hugo Kornelis, SQL Server MVP
Oct 25 '06 #2
Hi Hugo,
It worked! Thank you so much for the quick response!!. That's a very
elegant way to solve my problem.

Edy

Hugo Kornelis wrote:
On 25 Oct 2006 10:41:21 -0700, ed********@hotmail.com wrote:
I have a table called class_time. and the column name is start_time.
datatype is datetime.

id start_time
2 1900-01-01 15:00:00.000
4 1900-01-01 17:12:00.000

i want to the convert the start_time column into a format that only
has the hour and minutes plus AM/PM ( for example, 3:00 pm, 5:12pm)

id start_time new format
2 1900-01-01 15:00:00.000 3:00 pm

is there any simple one step way to do that?

(the only way i know is to use the following query, then do a substring
where the space is. but that's too complicated)
select CONVERT(CHAR(20), start_time, 22) from class_time

Thank you in advance for your time.

Hi eddiekwang,

Something like this?

SELECT STUFF(CONVERT(char(19), start_time, 100), 1, 12, '')
FROM class_time;

--
Hugo Kornelis, SQL Server MVP
Oct 25 '06 #3

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

Similar topics

3
by: Bob | last post by:
I am sure this has been answered in over whelming detail in this group, however the search results have not turned up any thing I am interested in. I want a simple form generator in PHP that...
1
by: Scott | last post by:
The following is the XML I have to work with. Below is the question <Table0> <CaseID>102114</CaseID> <CaseNumber>1</CaseNumber> <DateOpened>2005-06-14T07:26:00.0000000-05:00</DateOpened>...
1
by: Num | last post by:
Hi all, I have to convert a J2EE date as a long ("Millis") in a .NET date as a long ("Ticks") In Java, currentTimeMillis, is the difference, measured in milliseconds, between the current time...
2
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node...
4
by: michi | last post by:
Hello How can I convert a string to double with a decimal point as seperator? ***CODE**** strNumber ="12.00" dblDouble = Cdbl(strNumber) ****
10
by: Philip Wagenaar | last post by:
I have some code to convert a date to the unixdatetime representation (number of seconds since 1970). Only problem is that it only counts from the whole day, it ignores the times part. So convert...
5
by: mlafarlett | last post by:
Alright..I've found lots of info on this error and most say assign System.DBNull.Value, System.Convert.DBNull, or System.Data.SqlTypes.SqlDateTime.Null to my stored proc param and the problem will...
3
by: Joe | last post by:
Hi I have a dataset with 2 tables and Relations What is the best way to flatten the 2 files to a new table or xml or file I can loop thru table1 and get the childrows or I can do an Xpath on...
1
by: tvance929 | last post by:
I am making two tables in a DBASE - Giving and Members -- The Members has a primary key of HouseholdName with all the member details (address, name, etc.) --- The Giving table uses a PK ID. ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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...

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.