Results 1 to 4 of 4

Thread: algorithm help

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    algorithm help

    I am just not the usual me today and it sucks!!!

    I need some help.

    We have an object. it has a datetime property.

    What I want to do is to execute a certain condition IF TRUE.

    condition:

    if the object datetime hour == current hour (but should fail if the minute given as input is < current minute) or the hour given is > current hour and minute input can be of any value as long as the hour given is > current hour.


    does that makes sense? lol

    how can I make that into a conditional IF statement?

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: algorithm help

    actually I think I got it after re-reading this thread LOL

    but still I would like your suggestions!

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: algorithm help

    Correct me if I'm wrong but basically you want to test whether the time portion of a DateTime object is later than the current time of day, yes? If so you can use the fact that TimeSpan objects support the standard comparison operators.
    Code:
    TimeSpan inputTime = inputDate.TimeOfDay;
    TimeSpan currentTime = DateTime.Now.TimeOfDay;
    
    if (inputTime > currentTime)
        MessageBox.Show("The selected time is after the current time.");
    else if (inputTime < currentTime)
        MessageBox.Show("The selected time is before the current time.");
    else
        MessageBox.Show("The selected time is the current time.");
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: algorithm help

    well that is partially correct but I want to make sure that it does not "clash" with another time object but I have it sorted now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width