Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using MaskedEditExtender AjaxTools Control for time in my application how can i save only time-- in this format 11:23:22 AM/PM i have two column DataType is define as DateTime one is INTime (09:30:12 AM) and second one is OUTTime(06:30:12 PM) how can i write Insert query in Store Procedure.. HELP
I am starter with sql sevr and .net
i used DataType DateTime .....I think i use Time7 instead of datetime
Posted
Comments
Jignesh Khant 26-Jul-13 1:16am    
You can use 'DateTime.Now.ToShortTimeString().ToString()'.
Maciej Los 26-Jul-13 3:11am    
What version of MS SQL Server?
Have you seen this: Data types (T-SQL)[^]

Try This
SQL
Select Right(CONVERT(VARCHAR(25), GETDATE(), 22),11)
--Try above code for variable, Below one for Table..
Select Right(CONVERT(VARCHAR(25), ColumnName, 22),11) from TableNamee

Assuming that your column data type is DateTime and Version of Ms SqlSever is 2005 or above versions...
Hope this helps
 
Share this answer
 
v3
Comments
Maciej Los 26-Jul-13 2:41am    
Raja, please, improve your answer. You need to remember that there are few verions of MS SQL Server and their data types[^] are differ.
Raja Sekhar S 26-Jul-13 3:12am    
Maciej Los: Thanks for the Suggestion.. Updated the solution....
Maciej Los 26-Jul-13 3:23am    
This is not exactly what i wanted to see ;(
Please, see my answer.
A 4!
Raja Sekhar S 26-Jul-13 3:47am    
Thank you...
Please, read my comment to the question. We can't help you to write SP having not enough information.

Solution 1 by Raja Sekhar S is very good, but i would suggest to change data type of field to time (T-SQL)[^] if your MS SQL Server is 2008 or later.

Another way to return only time part of date is to use below query (without RIGHT function):
SQL
SELECT CONVERT(VARCHAR(25), GETDATE(), 114) AS CurrentTime


If you would like to insert time value into table, you shouldn't convert it into varchar data type. Save as it is. To view it, you can always use CAST and CONVERT (T-SQL) functions[^].
 
Share this answer
 
v4
Comments
Raja Sekhar S 26-Jul-13 3:45am    
But op wanted the time along with AM/PM... That's why i used the Right Function.. Other wise i would have suggested Time.....
Maciej Los 26-Jul-13 4:39am    
OK, i understand it now ;)
Faizymca 26-Jul-13 5:08am    
Thnx Raja Sekhar S, I meet to my requirement of time format but here my out this form
9:30:00 AM but i want (0) if value is 09:30:00 AM and i used Sql Server 2008 so can you suggest me which datatype i used in TIME7 or Date Time...
Maciej Los 26-Jul-13 5:21am    
Please, follow the link (posted in comment to the Raja's solution) and choose the best time format for you ;)
By The Way: Thank you for accepting my answer as solution ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900