Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai
i get time like 02:33:33 AM but how to save in sql server,i will use time,varchar,nvarchar but it only save time without AM or PM.how to save whole part in sql server.pls tell me which datatype can save and that datatype support asce or dsce order in sql querry.

Regards
ARavind
Posted
Updated 15-Nov-13 20:05pm
v2

Well, you could use the Time[^] datatype...


"thanx for ur reply,if i use break point and i will see 24 hrs format with literals,but after inserting into sql server it will time only ,not save literals and also 12 hr format only"

Depends on how you are inserting it. This works for me:
VB
Using con As New SqlConnection(strConnect)
	con.Open()
	Using cmd As New SqlCommand("INSERT INTO Table_1 (tm) VALUES (@TM)", con)
		Dim dt As DateTime = DateTime.Parse("01:33:33 PM")
		Dim ts As TimeSpan = dt - dt.[Date]
		cmd.Parameters.AddWithValue("@TM", ts)
		cmd.ExecuteNonQuery()
	End Using
End Using
 
Share this answer
 
v2
Comments
Aravindba 16-Nov-13 4:14am    
i will try with time(7),nvarchar(50) but it save only time without AM or PM like 11:22:40 only save in sql serrver,but i need 11:22:40 AM in sql server.or how to get time like 13:30:40 if
1 'o c***.i.e how to get current time in 24 hrs formate.
OriginalGriff 16-Nov-13 4:26am    
If you look at the link data, it always stores in 24 hour format - but it accepts strigns literals with AM/PM: look near the bottom at "Inserting Valid Time String Literals into a time(7) Column"
Aravindba 16-Nov-13 4:41am    
thanx for ur reply,if i use break point and i will see 24 hrs format with literals,but after inserting into sql server it will time only ,not save literals and also 12 hr format only
OriginalGriff 16-Nov-13 5:09am    
Answer updated
 
Share this answer
 

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