Click here to Skip to main content
15,867,305 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hai all
How to get time only with AM or PM in vb.net.i.e. 11:00 AM or 08:35 PM
or can get with ms also like 11:00:35 AM or 08:35:40 PM


pls reply asap

Regards
Aravind
Posted
Updated 1-Dec-21 4:10am

Try This:

lbltime.Text = System.DateTime.Now.ToShortDateString()
Dim d1 As String = DateTime.Parse(lbltime.Text).ToString("dd/MM/yyyy hh:mm:ss tt")
 
Share this answer
 
v2
Comments
Aravindba 16-Nov-13 1:38am    
thax this is work ,but below one direct convert
Label.text = Date.Now.ToString ("hh:mm:ss tt")
 
Share this answer
 
Comments
Ralf Meier 2-Dec-21 6:20am    
Please don't answer a more than 5 years old question with an answer which is allready given ... (see both Solutions before)
Bradley Schlangen 11-Mar-23 12:14pm    
Why? This answer is far better than the others.
Ralf Meier 11-Mar-23 15:44pm    
It's the same than Solution 2 - and your Reply goes to a more than one year old reply from me ... 🙄
Bradley Schlangen 14-Mar-23 11:43am    
It's not the same and it's far more elegant and minimalist. That solution answers the question in the most accurate and concise way possible and that makes the use easy to understand, which of course the very purpose of what this sites goal are. Are they not?

Why would you restrict posting alternatives or comments on this post simply based on the age of the post? How does that even make sense, as if there can never be a better or alternative way or commentary on it. Tell me the logic that lays there in your request please
Ralf Meier 14-Mar-23 13:29pm    
I'm sorry, Bradley ... but I see absolutely no difference between the Solution 2 and 4 and I also can't see why one of these Solutions is better than the other because both are using the same mechanism.
In fact it is no Problem to give an additional answer to an old question if it's different and/or a complete new approach - but in this case I see more the point which is called "Reputation Points Hunting" - and that is a very often used practise in this Forum. Perhaps you take a look at the "community" and there to the "Spam and Abuse watch".
But also for me there is no need to discuss this further - sorry ...
textbox1.text = format(now, "hh:mm:ss tt") hope it works for you
 
Share this answer
 
v2
Comments
Aravindba 16-Nov-13 1:38am    
Thnax it work,but in which data type can savein database ? sql server.i use date,time,nvarchar,varchar but only save time without AM or PM
ledtech3 16-Nov-13 12:01pm    
It would depend on what you would want to do with the data.
If you just want it as a string then you may have trouble sorting data by that column.

If you store it as a standard date/time then you can sort by that and "Display" it on a form how ever you want by converting it.
Sammy BM 1-Apr-16 4:33am    
That very helpful

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