Converting Time into a string (text field) (1 Viewer)

Ole

Registered User.
Local time
Today, 18:05
Joined
Apr 15, 2012
Messages
32
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?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:05
Joined
Oct 29, 2018
Messages
21,358
Hi. Welcome to AWF!

How about?

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

(untested)
Sent from phone...
 
  • Like
Reactions: Ole

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:05
Joined
May 7, 2009
Messages
19,169
it is hhnn.
mm is for month number.
 
  • Like
Reactions: Ole

theDBguy

I’m here to help
Staff member
Local time
Today, 10:05
Joined
Oct 29, 2018
Messages
21,358
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.
 

Cronk

Registered User.
Local time
Tomorrow, 04:05
Joined
Jul 4, 2013
Messages
2,770
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

Top Bottom