Need your help please. Covert time to army time, and trim off the date & am/pm

J

jonny

Option Explicit
Private mdTarget1 As Date
Private mdTarget2 As Date

' called on form load
Public Sub SetRecordStartTime()

mdTarget1 = DateAdd("n", 60, Time)
mdTarget2 = DateAdd("n", 120, Time)

End Sub

' I am using then using a if statement like "If Time > mdTarget1 And
Time < mdTarget2 Then"


Everything is working until after 12 midnight and then it returns for
example something like "10/10/07 12:00:00 AM" .

Can you help me do the following:

1st: Covert time to army time (1-24);
2nd: Only show the time and not the date or am/pm;


Your help would be greatly appreciated!!!
 
D

David R. Longnecker

If you need to format your time in 24 hour formatting, use the formatting
string HH.mm.

firstTargetDate = DateAdd("n", 60, Time)
secondTargetDate = DateAdd("n", 2550, Time)

Dim test As String
test = secondTargetDate.ToString("HH.mm")

The test variable then equals "04.16" which is 2550 minutes from when I coded
it, but yes, it does take the new day into consideration and prepend that
to the front. Just as long as you realize it's the next date, you can cut
the date part off with custom ToStrings. You don't want to totally get rid
of the date component (behind the scenes, presentation is another case) because
it is needed for proper calculation--you don't want 2100-0300 span to the
next day.

HTH.

-dl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top