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

Displaying time from Datetime datatype

Hi every one,
I am new to sql server2005,I have datetime column
in my database ..I need to display only time part of the datetime .I
need to display in AM/PM format ..datetime is stored in this format mm/
dd/yyyy hh:mm:ss AM/PM .I need to display in this format hh:mm:ss AM/
PM ,How can i do that?? I searched for this on net but i got 24hour
format .
i tried this on my own ,but no hope!

Thanks in advance,
Oct 31 '08 #1
2 3351
The DATETIME data type does not have format but it is rather stored as
binary value. Formatting is normally best done on the client side.

In T-SQL you can use the CONVERT function with style 109 and a bunch of
string manipulations to get the time formatted as string:

SELECT RIGHT('0' +
LTRIM(STUFF(RIGHT(
CONVERT(CHAR(26), CURRENT_TIMESTAMP, 109)
, 14),
9, 4, ' ')),
11);

--
Plamen Ratchev
http://www.SQLStudio.com
Oct 31 '08 #2
On Oct 31, 10:39*am, Plamen Ratchev <Pla...@SQLStudio.comwrote:
The DATETIME data type does not have format but it is rather stored as
binary value. Formatting is normally best done on the client side.

In T-SQL you can use the CONVERT function with style 109 and a bunch of
string manipulations to get the time formatted as string:

SELECT RIGHT('0' +
* * * * LTRIM(STUFF(RIGHT(
* * * * CONVERT(CHAR(26), CURRENT_TIMESTAMP, 109)
* * * * * * * * * * * , 14),
* * * * * * * * * * 9, 4, ' ')),
* * * * * * * 11);

--
Plamen Ratchevhttp://www.SQLStudio.com
Plamen Ratchev..
Thanks a lot for your help
Oct 31 '08 #3

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

Similar topics

1
by: Dave Posh | last post by:
I seem to be having a problem displaying time stored in mysql. The format stored in the database is 13:15:05. The database data type is time. I'm using asp vbscript and sql to retrieve the time...
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
0
by: vijayalakshmi.venkataraman | last post by:
Hello, I have a .NET client that accesses a Java webservice. Let me first say that the client stub I got generated from the wsdl was incomplete and had to make changes to it manually to make it...
3
by: Larry Bertolini | last post by:
For some reason, I recall having read that SQL Server 2005 would support a datatype that represented date, but not time. (This would be useful for storing things like birthday, where you usually...
6
by: rn5a | last post by:
I am inserting records in a MS-Access database table. The data type of one of the columns named *OrderDate* in the DB table is Date/Time. This is the SQL query I am using to insert the records in...
11
by: Matt F | last post by:
I'm trying to do something that seems like it should be pretty simple, but haven't found a solution. I am trying to add a datacolumn to a datatable that adds or subtracts a number of days based on...
1
by: Vajrala Narendra | last post by:
Hi am working with asp.net with backend Sql2000 i want to store NULL in datetime datatype field through coding. i wrote a update statement as Update table set Date1='NULL' where ........ but...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.