Converting Time into a string (text field)

Ole

Registered User.
Local time
Today, 19:36
Joined
Apr 15, 2012
Messages
44
Hi

I'm trying to convert Time (hh:mm) into a text string (hhmm). I'm using 24 hour not AM/PM.
It is working fine except when it's before 10 o'clock. When it's 09:15 the text string is 915 instead of 0915.
How do I keep the leading 0?
OpgaveStart is a Date/Time field (hh:mm)

My code is simple:
Dim TST1 As String
TST1 = OpgaveStart
TST1 = Format(OpgaveStart, "hhmm")
If TST1 > 100 Then
STUFORMAT = "0" & TST1
Else
STUFORMAT = TST1
End If

Any ideas?
 
Hi. Welcome to AWF!

How about?

Left(Format(OpgaveStar,"hh:nn ampm"),5)

(untested)
Sent from phone...
 
  • Like
Reactions: Ole
it is hhnn.
mm is for month number.
 
  • Like
Reactions: Ole
Working perfectly like this: Left(Format(OpgaveStart, "hhnn"), 5)

Thank you :cool:
Hi. Glad to hear you got it sorted out. We were happy to assist. Good luck with your project.
 
Would have been a lot simpler if the OP had made the comparison with a string

If TST1 > "100" Then
 

Users who are viewing this thread

Back
Top Bottom