I am having problems formatting time in visual basic. I need it to be in 24 hour time without the AM or PM at the end. So if I wanted 1:29pm (12-hour) it would come to be 13:29
Thanks
13 28202
I am having problems formatting time in visual basic. I need it to be in 24 hour time without the AM or PM at the end. So if I wanted 1:29pm (12-hour) it would come to be 13:29
What version of VB?
In VB6, you should be able to use Format(YourDateTime, "hh:nn").
I think it should be format("HH:mm)
the uppercase HH represents 24 hour time.
the lowercase hh represents 12 hour time.
Peter
the uppercase HH represents 24 hour time.
the lowercase hh represents 12 hour time.
Does it? That's odd, I tested my suggestion before posting and it worked. Perhaps it depends on VB version, or Windows regional settings.
well windows died on me, so im running on a 40GB hard drive.
I had (reinstalling now) VB6.
And I recovered all my data succesfully, so I will try this soon.
Thanks!
One more question, if I convert it to 24 hour time, then send it to a string variable, will is still work using the < and > (less than/greater than) statements on it. Cause it works if you just use [text1.text = time] and then in a timer just have like
If text1.text = > 12:32:01 PM then
text2.text = "Lunch is over"
end if
cause thats worked for me so far. The only reason that I need 24 hour time is because VB doesn't regognize if it is AM or PM. So even if its > 12:32:01 AM the code will still run.
Thanks Again!
Cheers
I'd say the problem there is just that you're comparing string. So all it's doing is looking at the characters in the string, one by one, not the actual time value. As a string, "2:13 AM" is greater than "12:54 PM" simply because the character "2" has a higher ASCII value than "1". If you convert them to an actual time value of course, it's a different matter.
If you want to compare times you're better off converting back and forth as required. Working with strings that represent things like a date or time is very risky, as the format can change from one PC to the next.
Tip - in many cases it's better to use something like a datetime picker control rather than a textbox. In some cases, I've also used one or two labels to display a time value, with a couple of "spinner" or "updown" controls for the user to adjust the time. If you let people type in a value, they will always find some way to stuff it up.
(In fact I had to debug a case like this just recently, where the user entered a time of "15:3O". Which looks alright, but most certainly isn't. Try copying and pasting it if you don't believe me.)
could you please just give like an example code for the 24 hour format. If i do this:
Private Sub Timer1_Timer()
Text1.Text = Time & Format("15:30", "HH:mm")
End Sub
the text box will give me this
5:28:19 PM 15:30
thanks
- Private Sub Timer1_Timer()
-
Text1.Text = Format(Time, "HH:mm")
-
End Sub
Is this what you're after?
Also, for your comparison I think you can use something like this... -
If CDate(Text1.Text) > CDate("12:30:59") Then
-
Text2.Text = "Lunch is over"
-
End If
Of course, ideally you'd ( A) validate Text1.Text first to ensure it's a proper time value, and ( B) use a constant (or variable) for the end of lunch, not hard-code a string in the test like this and convert it every time.
- Private Sub Timer1_Timer()
-
Text1.Text = Format(Time, "HH:mm")
-
End Sub
Is this what you're after?
THANK-YOU...thats all I needed...lol
THANK-YOU...thats all I needed...lol
Glad we could help. :)
You all can use this :- DateTime.Now.ToLocalTime.ToString
The Output :-
30-Mar-14 2:51:15
You can do this
[Text1] = Format(Time, "HH:mm")
Result is your current time with 24 hours format
Example 3pm
15:00
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Gord |
last post by:
Hello,
VB6 accepts Date and Time values as 'Date'. I'm trying to verify entry into
a database I'm creating by verifying that an appropriate Date or Time value
has been entered. Using built-in...
|
by: T-Narg |
last post by:
I would like to produce the following output based on my XML file:
My Album (2005)
Elapsed Time (hh:mm:ss): 00:07:00
Song 1: title1
Length (hh:mm:ss): 00:02:30
Song 2: title2
Length...
|
by: Kenneth |
last post by:
Hello,
I'm having some serious problems debugging a script that I'm trying to make
work. I'm working on a form where a user can type in a time (in the format
of HH:MM), and another script...
|
by: Rene |
last post by:
I am currently displaying the time of day value using the "h:mm:ss tt"
format (hr=hours, mm=minutes, ss=seconds tt=AM/PM).
I was looking under the "Regional and Language Options" and it looks...
|
by: Edward Mitchell |
last post by:
I have a number of DateTimePicker controls, some set to dates, some set to a
format of Time. The controls are all embedded in dialogs. I created the
controls by dragging the DateTime picker from...
|
by: scorpion53061 |
last post by:
What I thought would be pretty easy has turned out not to be.
I have three variables. Actiontime is formatted as 08/11/2004 11:03PM
Actiontime
JobStreamStart (11:00:00PM)
JobStreamEnd...
|
by: Khurram |
last post by:
I have a problem while inserting time value in the datetime Field.
I want to Insert only time value in this format (08:15:39) into the SQL
Date time Field.
I tried to many ways, I can extract...
|
by: Jerome |
last post by:
Hallo,
I know a lot has already been told about date/time fields in a database but
still confuses me, specif when dealing with SQLserver(Express).
It seems that sqlserver only accepts the date in...
|
by: Dirk Hagemann |
last post by:
Hello,
From a zone-file of a Microsoft Active Directory integrated DNS server
I get the date/time of the dynamic update entries in a format, which
is as far as I know the hours since january 1st...
|
by: nospam |
last post by:
I have some data that I need to run date diffs on. The catch is that
for some of this data, there is a date value in one of the fields,
with no time. It might look like this:
ROW DT1 ...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |