VB.net code for this?

If lblTIME.Text(Code for between a time eg:    05 to 12) Then
End If

        lblTIME.Text = DateTime.Now.ToString("HH")
        lblDATE.Text = DateTime.Now.ToString("yyyy-MM-dd")

        If lblTIME.Text = (??????????????????????) Then
        End If

Open in new window

Rowel VirgoVisual Studio .NETAsked:
Who is Participating?
 
Ryan ChongCommented:
try like:

lblTIME.Text = DateTime.Now.ToString("HH")

Dim t as integer = convert.toint32(lblTIME.Text)

if t >= 5 and t <= 12 then
  'your stuffs....
end if
0
 
Nitin SontakkeDeveloperCommented:
Why not instead access the integer property which is readily available, DateTime.Now.Hour. For consistency, you may wish to assign it to a variable instead and then verify.
1
 
Rowel VirgoVisual Studio .NETAuthor Commented:
I did this,

If lblTime.Text >= 5 AndAlso lblTime.Text <= 12 Then
0
 
Nitin SontakkeDeveloperCommented:
This is all fine, if it is working, however, I feel uncomfortable even looking at it as the whole concept of data-types is being dishonoured (not finding appropriate word...) in which a lot of thinking and design decisions have gone in, for example, generics.

I had rather...

Dim intHour As Int32 = DateTime.Now.Hour
lblTime.Text = intHour.ToString("00")
If intHour >= 5 AndAlso intHour <= 12 Then
   ...
End If

Open in new window


Think about it...much better, in my opinion.
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.