Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai
How to get current Time with Am and Pm in vb.net and sql ?
like 11:00 Am or 02:20 Pm (or 2:20 Pm).No need secs,ms and so... and what datatype need to give sql server column for capture in the table ? navarchar() or varchar() smalldatetime or Date or Time.


note: i need to save time with Am and Pm (11:00 Am )in sql server.



Regards
ARavindb
Posted
Updated 10-Dec-13 21:44pm
v2

Use datatype as
DateTime

And to get datetime in specified format use
CONVERT(VARCHAR,GETDATE(),119)
function. And for more details please refere -> http://www.w3schools.com/sql/func_convert.asp[^]
 
Share this answer
 
v2
Dim a As String = DateTime.Now().ToString("hh:mm tt")
i will get what i except like 02:20 Pm
 
Share this answer
 
v2
Comments
Goenitz 17-Dec-13 21:45pm    
What if i have a user input time? for example the user input is 08:00 AM(STRING) how can i convert it to time?
Aravindba 18-Dec-13 0:00am    
user manually enter time ? but in my above answer is get current system time and convert as string
Goenitz 18-Dec-13 0:12am    
I said "what if" :), if its the case how can i convert it to time?
Aravindba 18-Dec-13 0:19am    
Dim a As DateTime = DateTime.Now().ToString("hh:mm tt") try like this,it will get time as datetime,if u declare variable as DateTime then it is time not string
Goenitz 18-Dec-13 2:04am    
Lets make this clear, I have a string variable = 08:00 AM , now how can i convert this to time data type so that my database will accept it?
Aravindba wrote:

note: i need to save time with Am and Pm (11:00 Am )in sql server.


Bad design!
You should store date as date data type not as varchar for set of resons:

  • query performance

  • database performance

  • easiest way to operate on data

  • etc.
 
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