Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Converting Time In (AM/PM) To 24 Hour Format?

Hi guys...

How do i convert my time in AM/PM to 24 hour format?? Thanks!!


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
24 Hour Time Format
is there a 24 hr date/time format in vb? e.g. format(txtblabla, 'mm/dd/yyyy hh:mm HH24)?

12/24 Hour Time Format
Can anyone recommend a reliable method of determining whether times should be displayed in 12 or 24 hour format on a user's system. I know how to format times either way, but I'm looking a way to determine how the user would like hours to be represented only. The regional settings in the Control Panel allow to specify the time format for full times, but I'm looking to display hour names at the top of a grid.

12 Hour: 12A, 1A, 2A ... 10P, 11P
24 Hour: 00, 01, 02 ... 22, 23

I want to select which display to use based on the regional settings, but there seems to be no simple setting for this. I thought of checking the Time Format string for the presence of the "t" character, but will those same "h", "m", and "t" characters be used in all foreign systems where a different language is possibly in use?


Resolved - 24 Hour Time Format
How can I use the Format function below to return time in a 24 hour format?
Code:dim strTimeCys
strTimeCys = Format(Time, "hh : mm : ss")


Edited by - ddutke on 2/13/2005 10:37:27 AM

Format Time To Display Closest Hour
I've been using this:

VB Code:
Format(Time, "h AMPM")

to diplay time (hour). Problem is that using the above 3:54 PM will show as "3 PM"

How do I format the time to display the closest hour? (so that 3:29 will show 3 PM and 3:31 will show 4 PM)

Convert Numeric Value In Time (hour-minute) Format
Hello All,

I have requirement of your help, I need to convert Numeric value in Time(hour-minute) format using single function becuase it's required in query.

Numeric value as 8.61 it's convert into 9.01 using single function.

Pls help me. it's very urgent.

Thanks in Advance.

Converting UNIX Time In Milliseconds To Normal Date Time Format?
Hi all. Dont know if this is common or not. Did a search, but found nothing.

I have got a 48 bit date and time value represented in hex being generated on a unix system. The 8 byte date and time is measured from epoch 1(1 Jan 1970, midnight) in milliseconds, ie. the Unix hex data is one extra long number in milliseconds.
I want to convert this to a readable format such as: mm/dd/yy hh:mm:ss.sss

I have some examples taken from some other program runing on Unix system:
Unix data - 7E E6 64 B7 FF 00 (no idea how to convert this to equivalent)
equivalent - 10/20/04 17:31:43.614

Unix data - 5D 2D 26 F5 00 01
equivalent - 12/21/04 10:22:27.677


Convert From 12 Hour To 24 Hour Time ***RESOLVED***
I don't want to change the user's regional settings. I want to figure out what the time is (in 24 hour time), regardless of what the user's regional settings are.

Converting Time Format!
Hi all, I am working on a payroll project and I have an attendencemodule, which extracts the values from a delimited text file and savesit into SQL server database table.. . now I want to find the durationbetween two times specified in that table ..the problem is, in thatfile, the time-in and time-out are shown as follows.



now how to I calculate the duration? right now, if anyone can tell mehow to convert the aforementioned time to normal time, I would beobliged.. thanx..

Converting Time Format:
Hi all, I am working on a payroll project and I have an attendence module, which extracts the values from a delimited text file and saves it into SQL server database table.. . now I want to find the duration between two times specified in that table ..the problem is, in that file, the time-in and time-out are shown as follows.


now how to I calculate the duration? right now, if anyone can tell me how to convert the aforementioned time to normal time, I would be obliged.. thanx..

Converting Tot Min To Time Format (not 10ths)
Does anyone know how I can convert total minutes to hr and minutes (stnd time format)?


90 to 1.30


Converting Whole Number In Sec To Time Format
How would you convert a whole number in seconds like 2525353 to be in the hh:mm:ss format? I have tried using format and it doesnt convert it correctly any help?

Converting One Date/time Format To Another.
Hi all,

What I have is a "Sales Order" text file that I import into a tmptable. This table is used to check for duplicate orders from the customer. If there is not duplicate orders it is then written to a Orders table.. what I need to do is convert the date/time format that is imported..

The date/time looks like this.. 2004-06-04T23:07:34-07:00
searching the net I think I found the format. YYYY-MM-DDTHH:mm:ss-zzz

What I need to do is have this converted to MM/DD/YYYY when I am writing it into the orders table...

I am using VB6 with Recordsets to write data into the orders table.


Converting Variable To Time Format
hi guys,

i would like to know how it is possible ot convert integers into time format

in my project i have two integers
"seconds" & "minutes" and they hold those things respectivly. What i need to do is add those together and then add that time to the current time to display a date in the future

later i will also need to subtract those two final dates for wihch i have found fuction datediff

Code:lngHowLong = DateDiff("n", Text1, Now)

i assume this will work

sorry for vagueness i cant explain it to well


Converting Double Back To Time Format
Hi I would like to find out how i can convert a double back to time format. I know how to convert time to a double.
When i convert 01:00 to a double it gives me this answer: 4.16666666666667E-02 When i try to reverse it suddenly a 01:00 becomes a 01:10

The formula i use to convert the time is
((Hours * 3600) + (Minutes * 60)) / 86400

pleas help?!?

Converting A Julian Time To Standard Date Format
I am looking for help on converting a Julian time (1970) value to standard date and time format. Any help would be greatly appriciated.

Converting UNIX TIMESTAMP To Access Date-Time Format
Hi All,

Importing/Linking tables into ACCESS-97 via ssh through ODBC connection to My-SQL.

Dates are in UNIXTIMESTAMP format.

Is there a conversion script available
for free to convert the long integer to an access date-time format ?

Would like to be able to report on date ranges without copying, modifying and or duplicating the fields.
Writing VBA function(s) to return number of days

Function LeapYear(YearInput As Integer) As Boolean
LeapYear = False
If YearInput Mod 400 = 0 Then
LeapYear = True
If YearInput Mod 4 = 0 And YearInput Mod 100 > 0 Then
LeapYear = True
LeapYear = False
End If
End If
End Function

Function DaysInFullYears(YearInput As Integer) As Long
Dim i As Integer
DaysInFullYears = 0

If YearInput < 1970 - 1 Then
For i = YearInput To 1970 - 2
If LeapYear(i) Then
DaysInFullYears = DaysInFullYears + 366
DaysInFullYears = DaysInFullYears + 365
End If
Next i
DaysInFullYears = -DaysInFullYears
End If

If YearInput > 1970 Then
For i = 1970 To YearInput - 1
If LeapYear(i) Then
DaysInFullYears = DaysInFullYears + 366
DaysInFullYears = DaysInFullYears + 365
End If
Next i
End If

End Function
Function DaysInFullMonths(YearInput As Integer, MonthInput As Integer) As Long
Dim DaysInMonth(12) As Integer, i As Integer
DaysInFullMonths = 0

DaysInMonth(1) = 31
If LeapYear(YearInput) Then
DaysInMonth(2) = 29
DaysInMonth(2) = 28
End If
DaysInMonth(3) = 31
DaysInMonth(4) = 30
DaysInMonth(5) = 31
DaysInMonth(6) = 30
DaysInMonth(7) = 31
DaysInMonth(8) = 31
DaysInMonth(9) = 30
DaysInMonth(10) = 31
DaysInMonth(11) = 30
DaysInMonth(12) = 31

If YearInput < 1970 And MonthInput < 12 Then
For i = MonthInput + 1 To 12
DaysInFullMonths = DaysInFullMonths + DaysInMonth(i)
Next i
DaysInFullMonths = -DaysInFullMonths
End If

If YearInput > 1970 And MonthInput > 1 Then
For i = 1 To MonthInput - 1
DaysInFullMonths = DaysInFullMonths + DaysInMonth(i)
Next i
End If

End Function
Function DaysInMonth(YearInput As Integer, MonthInput As Integer, DayInput As Integer) As Long
DaysInMonth = 0

Select Case MonthInput
Case 1, 3, 5, 7, 8, 10, 12
DaysInMonth = 31
Case 4, 6, 9, 11
DaysInMonth = 30
Case 2
If LeapYear(YearInput) Then
DaysInMonth = 29
DaysInMonth = 28
End If
Case Else
DaysInMonth = 0
End Select

If YearInput < 1970 And DayInput <= DaysInMonth Then
DaysInMonth = -(DaysInMonth - DayInput) - 1
End If

If YearInput >= 1970 And DayInput <= DaysInMonth Then
DaysInMonth = DayInput - 1
End If

End Function

Function DaysSince01011970(MthVal As Integer, DayVal As Integer, YearVal As Integer) As Long
DaysSince01011970 = 0

DaysSince01011970 = DaysInFullYears(YearVal) + DaysInFullMonths(YearVal, MthVal) + DaysInMonth(YearVal, MthVal, DayVal)
End Function

long integer value for a date (not going to worry about the time)

Is there anything out there already written that can be called from an Office 97 application


Hour Format

(No VBA this time, only number formats and fomulas if possible)

I want to sum hours (9 h 00;8 h 00; 8 h 15)

But when my sum goes over 24 hour it restart at 00 h 00

9 h 00 + 8 h00 + 8 h 15 = 1 h 15

I want it to be 25 h 15... Is it possible and how?

24 Hour Format
Hi All,

I have this line of code that creates a time for me, but how do I get it to be a 24 hour clock?

VB Code:
Label1(0).Caption = Format$(Now, "Long Date") + "   " + Format$(Now, "hh:mm am/pm")



SystemTime In 24 Hour Format
I'm trying to show UTC and local time in a 12 and 24 hour format. Im using the following code:

Private Sub Timer1_Timer()

GetSystemTime zt

txt12.Text = Right(DateAdd("h", -5, Format(zt.wHour, "00") & ":" & Format(zt.wMinute, "00") & ":" & Format(zt.wSecond, "00")), 11)

txt24.Text = Right(DateAdd("h", -5, Format(zt.wHour, "00") & ":" & Format(zt.wMinute, "00") & ":" & Format(zt.wSecond, "00")), 11)

txtZT.Text = Format(zt.wHour, "00") & ":" & Format(zt.wMinute, "00") & ":" & Format(zt.wSecond, "00")

End Sub

txt12 is my 12 hour format local time an txtZT is my UTC. They both work fine. I can't figure out how to format to make it local time in the 24 hour format. I've played around with a couple of different things but the best I can get is the local time in 24 hour as a time stamp. Any thoughts would be appreciated. The above code is just where I left it to put it in this thread.



Format DTime For 24 Hour
I use dShowClock as date to hold time data. Can ot be set to store in 24 hour format. Now I use format function to convert to 24 hour but I would like to omit the extra step. I would like dShowClock to hold 24 hour format so I dont need the strTestClock


dShowClock as date

dShowClock = DateAdd("H", SystemClock(2), dShowClock)
strTestClock = Format(dShowClock, "Hh:MM:SS")



VB.6 User, Since 2002
Next Generation Lighting Controls

Access - Convert Short Time To 24 Hour Time

I have table fields that are formatted with short time input mask.

I need to convert the data to twenty-four hour time (without AM/PM).

Example - 4:30 AM converted to 04:30.

If need be, I can change the Date fields of the table to text, or whatever. I have the form fields formatted with a short date input mask.

I was able to convert the short date to YYYY/MM/DD, with some googling, but I can't find anything on converting the time to twentyfour hour time.


SQL Server Date Hour Format
Here is my problem :
I am saving in an SQL Server database a Date Time Value (i.e : 01/10/02 15:15PM ) and I would like to be able to make a search on the date only via SQL language ( without considering the Time value ).
I tried about everything, from the LIKE keyword to the simple query ( Where Date = '01/10/02' )
It never returns any results because 01/10/02 is not the same time than 01/10/02 15:15PM ...
Anybody has a clue on how I can search the date value only ( and my program is already distributed, so it is a little bit too late to create a cloumn for date and another one for time...)
Thank you in advance...

Formatting Date Picker To 24 Hour Format
Hello All
I am stuck in a problem
I have placed the date picker and changed the format to 2-dtpTime. Now it is showing 12:00:00AM.I want to set the date picker to show time in 24 hour format.Please tell me how do i do this?

Thanks in advance

Set The Time To One Hour
My program is to establish a connection between a client and server to send the IP address of client. This is done automatically in every one hour. The IP address can be sent automatically to the server but the problem is how to set the time to one hour to send next IP address to the server. I try to do this by using a timer control but the constraint is the timer interval properties can only be set to 65000 which is about 1 minute. I would very much appreciate if somebody could help me. Thank you.

1 Hour Time

I'm new here

I've a question: I need to use a timer in my application but it has to start every hour. VB timer can't do this

How can I do?

many thanks


24-hour Time Trouble
I am having some trouble with this part of my code as I am only new to vb. I have to have 2 text boxes (named txtstart and txtend) in which the start time of the meeting and the end time of the meeting are entered and I have to show the amount of time that the meeting will run for. I have worked out that a simple

lblmeetingtime.caption = txtend.text - txtstart.text
will work, but the problem is that when an end time like 1600 or 0100 where there are 2 zeros at the end the code gives me a number out of 100. How can I fix this without having to hit my head on the wall
BTW, its in 24 hour time.


Hour(time) Function
I use the hour(time) function, but i want it formated in single digit 12-hour format. But it doesn't work with:
format(hour(time), "h")

Please help me out here. Thanks

Calculate Time (24-hour)
for example:
time-A: 1749
time-B: 1555
how to count: how many minutes between time-A and time-B?
or is there VB library can do for this?

SQL, Adding An Hour To Time.
When booking appointments i do nt want to double book one member of staff at any time, each appointment can be 1, 2,3 , 4, 5, 6 hours. And the time of the bookings are on the hour.

When the user wants a 2 hour appointment i want to search the database i am using to see if an appointment has been made for the hour they have selected, and the every hour.

I have used this for a date once...

VB Code:
SQLTXT = SQLTXT + " WHERE [Date] BETWEEN #" & Now & "# and #" & DateAdd("d", 7, Now) & "#"

Any ideas


Get Hour Of Time - Dtpicker
how would i get the hour of the time and put it in text1
and get the AM/PM of the time and put it in text2?

help pls...

Convert To 24 Hour Time
I really need to know how to convert time that is in this format 04:05:00 PM to 24 hour time 16:05.. Please help!! Also is there a funtion that will calculate the difference in hours between to times? And can I convert the anser to an long number?

Converting Microsoft Binary Format To IEEE Format Using VB 6
I wrote an accounting package back in the late 80's, early 90's that began back with GWbasic and so on upto Professional Development System ver 7.10. All the Data that was saved to random accessed files using the old unsupported Microsoft Binary Format (MBF). 10 years later the firm now wants me to develop a windows version of the software. I've come to a snag in development right from the start where MS VB no longer supports the MBF format. There are 3 function I need, they are CVI (integer), CVS (single), CVD (Double), these convert MBF strings to thier respected ieee Decimal format. I've been searching the net for about a week trying to find a method to do this and have come up against a brick wall. if anyone is able to assist me in my problem please feel free to add your advice. Anything is better than what I've come up with so far.


How To Test On Time (hour) Change
I have a timekeeping program that keeps time fine; however, the system also displays the date which is supposed to always be current. The problem is that when the date changes at midnight, the timeclock screen does not.
Here is the line of code that displays the time:


lblHr = Format(Time, "hh:mm:ss AMPM")

I have a routine that diplays the system date when the program starts. What I want to do is invoke that routine every time an hour change occurs. That way, I will catch the Windows date change when it happens. I do not know how to test for an hour change.

Can someone help please?

CPU Time 2-3 Seconds Every 1/2 Hour. Is That Normal???

I have a VB app that has a timer, and sub-classes system message for when system changes, or time changes etc...

I have noticed that the application consumes 2-3 seconds of CPU time every 1/2 hour. Is that normal? Is there a way of knowing what the application is doing exactly to consume that time?

12-hour Time Function Syntax
Hi all,

I'm making a clock-type program, and it outputs the time to a label, updating it with a timer (the timer code has "Label.caption = Time"). However, I have a checkbox that will allow the user to tick to display the time in a 12-hour format rather than 24hour. I've looked on MSDN as the format:time function, but I don't think it's what i need, either that or I'm not implementing it properly.

So basically, how do I use the "Time" function output 12-hour time?

How Do I Deduct An Hour From A Time Field?
I have two date/time vars, PickupTime and ReturnTime . I also have a var called GracePeriod, which is an integer.

What I need to do is calculate if a rented car has been returned later than the ReturnTime, if so add an extra day to the total days rented (and charge them extra muhaha).

If PickupTime < ReturnTime Then
RentDays = RentDays + 1
End If

So in the above example, if the user types in 9:00 for the PickupTime, and 9:01 or greater for the ReturnTime, the RentDays goes up by 1. But sometimes there is a "grace period" e.g. if set to 1 allows the car to be returned an hour later than the ReturnTime without the penalty of an added day. So I need something like this:

If PickupTime < ReturnTime - GracePeriod Then
RentDays = RentDays + 1
End If

However I obviously can't subtract an integer from a time. So how can this be done?



Anyone For A Real-Time Twelve Hour Clock?
I need a twelve hour clock that can display, hours, minutes and seconds. As well the AM and PM, when they are required in the sequence of time. I am going to use a TextBox, which is called "Text1".

Time (hour) Control Idea Needed...
I'm doing a program to a parking company that controls the price by hour.

I thought in 2 ways to control it:

1 - Start a timer when the car arrives;

2 - Check the system time when the car returns.

On the first case, the problem is that if the program is closed, the timer will stop. The second case's problem is the user can change the system time.

Do you have any idea to help me?


Converting Bitmap Images To AVI Format, Then To DVD Format
I found this website for converting a series of bitmap images into an AVI format video:

I used it in my VB6 program, and it worked great. I can make AVI animations. Now I am interested in burning my AVI animations on DVD so I can watch them on my friend's television. Are there any similar code snippits that will do that for me without being a genius at programming?

Hour(Time) Function; Similar One For Seconds/Minutes?
Are there functions in VB6 that return the minutes and/or seconds of a time variable like the Hour() function that takes a time as its parameter and returns the hour?

What Should I Concern For A 24-hour Long Time Running Programe?

I had made a programme that will be non stopping running on 24 hours.
but i find that it keeps hanged for every week so i need to restart the computer. (it's running in win xp Home)
i think it may out of memory and the progamme always insert and update some data to an Access DB. Do i need to type some code to release the memory and what should i concern for a long running progamme

Thank you very much~

How To Restrict The Time A User Can Be Logged On For In Any 24 Hour Period
I have a stand alone pc running under xp home edition. I want to restrict the login duration on some user accounts over each 24 hour perod. Can anyone please suggest code I may need and where to put it.
Thank you very much.

Converting +/- 180 Degrees Format Into +/- 90 Format
I'm pretty bad at math, however I need to answer a math problem.

Here's the situation:

There's a circle. It's setup like this:

-90 90

(edit: having a bit of formatting issues here, with spaces, but you get the idea)

How can I convert that degree-format into a +/- 90 degree format?


-150 would be -30 degrees (+150 would be 30)
-120 would be -60 degrees (+120 would be 60)

I would need the code to take the -150 number, and output -30. If the input was 150, the output would need to be 30. Obviously not just those numbers, it would be for every degree.

Is this doable? I can't get the logic behind doing such a thing, really wish my math was better. :/

Edited by - ThisIsMyUserName on 3/17/2006 1:05:32 PM

Converting Mp3 Format To Wav
Hey. Just saying, you can use winsock to do that if you want.

Converting VB3 To VB5 Format
Is there a program out there that will convert a program written in VB3 to VB5.  I am a novice programmer but have written an extensive program in VB3 which I use at work.  We have converted to a server which is operating under MS Server 2003 and it is not handling the 16 bit program at all well.  I have VB5 as well and would like have it run as a 32 bit program.  Any suggestions short of hand coding the entire thing?  I know that I can save all my forms as text and open them in the VB5 environment, which I have tried but the controls are messed up.  Help!

Converting A Number Format
is there a way to convert a number like this "12:07:02" to this "12.07" using EXCEL Vb

ive tried format cell number etc that dont work is there a way to edit the cell contents or a way in which you can send key strokes in to a cell to remove the end 2 numbers and replace the ":" with a "."

Converting A File Format
Hey, im looking to make a program to convery MP4 -> MPEG, is this possible in VB, or Delphi?, and if so how can i?

Converting One Date Format To Another?
I have a date in YY/MM/DD format and when I use CDate it mixes the day and year, how can I convert it from this YY/MM/DD format to a date format? Changing the YY/MM/DD format of the input date is not an option.


Converting Hex To Decimal Format
Here is what I am trying to do. I have a card reader that reads in an 18 digit decimal number. I then have my program convert that number to hexidecimal format. I am now trying to take that database and re-convert the hexadecimal number into the original 18 digit decimal format. When trying to use the following code I keep getting an overflow error, however, it does work on smaller Hexadecimal numbers. Does anyone have any suggestions? I really need help fast, I am on a very short deadline! Thanks to all!!

Private Sub Command1_Click()
Dim sHex As String

sHex = 2EEC07E9A9
MsgBox Hex2Dec(sHex)
End Sub

Function Hex2Dec(sHex As String) As Long
Hex2Dec = Val("&h" & sHex)
End Function


Copyright 2005-08, All rights reserved