Home All Groups Group Topic Archive Search About

working with time only

Author
13 Jun 2006 9:01 PM
cj
If I want to check to see if it's after "11:36 pm" what would I write?

I'm sure it's easy but I'm getting tired of having to work with dates
and times.  Sometimes I just want time or date.  And to be able to do
comparisons on them.

Author
14 Jun 2006 3:08 AM
Jeffrey Tan[MSFT]
Hi CJ,

Thanks for your post!

The time in the day is logically associated with the date. So you can first
get the exact time then get rid of the date party of the time. Below code
snippet shows a sample to do this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        Dim dt1 As DateTime = DateTime.Now
        Dim dt2 As DateTime = New DateTime(dt1.Year, dt1.Month, dt1.Day,
23, 36, 0)
        If (DateTime.Compare(dt1, dt2) > 0) Then
            MessageBox.Show("Current time is greater than 11:36 PM")
        End If
    End Sub

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Author
14 Jun 2006 6:32 AM
Cor Ligthert [MVP]
cj,

If you initialize a new datetime than it is initial set to the start of the
christian calender 01-01-01 00:00:00

Therefore if you ignore the datepart in your program you have just a time
and can work with them. As forever you have to show dates and time to use
the overloaded function of ToString which is in the DateTime.

http://msdn2.microsoft.com/en-us/library/ht77y576.aspx

I hope this helps,

Cor


Show quoteHide quote
"cj" <cj@nospam.nospam> schreef in bericht
news:eiceVyyjGHA.4660@TK2MSFTNGP03.phx.gbl...
> If I want to check to see if it's after "11:36 pm" what would I write?
>
> I'm sure it's easy but I'm getting tired of having to work with dates and
> times.  Sometimes I just want time or date.  And to be able to do
> comparisons on them.