Question: Time comparisons

V

VB Programmer

I want my web page to take the current time and either say "Good
Morning/Afternoon or Evening". Any ideas how I can do this? I tried this
but it's taking the times as strings...

Dim strMyTime As String = Now.ToShortTimeString

If strMyTime < "11:30 AM" Then
Response.Write("Good Morning")
ElseIf strMyTime > "11:30 AM" And strMyTime < "4:30 PM" Then
Response.Write("Good Afternoon")
Else
Response.Write("Good Evening")
End If


Thanks!
 
L

Lucas Tam

I want my web page to take the current time and either say "Good
Morning/Afternoon or Evening". Any ideas how I can do this? I tried
this but it's taking the times as strings...


Use the functions: Hour, Minute.

So something like

If Hour(Now()) < 11 and Minute(Now()) <= 30 then
lblTextBox.Text = "Good Morning"
End If

There's probably a more elegant want, but I'm brain dead.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top