Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I properly format time?

Status
Not open for further replies.

Ken011

MIS
Oct 13, 2006
66
US
Hi everyone:

How can insert : (colon) in time, while ensuring that the colon that currently exists doesn't get removed?

What I mean is that we have users who use our application to process certain time-critical information.

sometimes, they enter time as 930 (9:30) or 1100 (11:00). Some other times, the same informaton is entered with colon.

My question is this, how can ensure when time is entered in the format described above, that the time is properly formatted?

For instance, if they enter time as 930 or 1145, then they are properly converted to 9:30 or 11:45 respectively.

By the same token, if it is entered correctly such as 9:30 or 11:45, the script that does the conversion, doesn't mess the correct format up?
Thanks in advance
 
From your profile it looks as though you haven't had much success with this forum, as you seem to have asked 5 questions, but haven't yet thanked any of the responders or marked any of the answers as valuable. May I suggest you read faq222-2244 carefully for guidance on getting better answers. If you've had help from the answers, the FAQ will show you how to acknowledge them.

For this question, try starting from this - you will need to be a bit more rigorous with error checking for production code of course!

Code:
x=inputbox("time")
If Instr(x,":") = 0 Then 'check for colon
x=Left(x,Len(x)-2) & ":" & Right(x,2) ' insert if req
End If
If isdate(x) then 'check for validity
Msgbox x
Else Msgbox "Invalid time"
End If

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
I always and truly appreciate all responses, whether my problem is solved or not.

Thanks very much for your assistance
 
I prefer to limit the damage that users can attempt to do. So I use two select boxes for hours and minutes

I just read this and realized how painful it will be to come up with minutes in a dropdown.

I can see about hours because all you need is come up with numbers from 1 to 12 but minutes?

I must be missing something.
 
Is there something difficult about;
Code:
<select name="minutes">
<%
dim x
with response    
for x = 0 to 59
    .write "<option value="
    .write chr(34)
    .write x
    .write chr(34)
    .write ">"
    .write str(x)
    .write "</option>"
    .write vbCRLf
next
end with
%>
</select>
??


Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top