Closed Thread
Results 1 to 4 of 4

Thread: how to validate time hhmm

  1. #1
    zabbath is offline Newbie
    Join Date
    Jan 2009
    Posts
    3
    Rep Power
    0

    how to validate time hhmm

    Hi,
    i'm new to programming and i'm writting a simple program, can anyone help me how to check valid time group,

    Example :

    when following reports are paste on textbox

    1. xxxx xxx 2101 xxx xxx. (2101 is time group in GMT)
    2. xxxx xxx 2355 xxx xxx. (2355 is time group in GMT)
    3. xxxx xxx 0050 xxx xxx. (0050 is time group in GMT)
    4. xxxx xxx 0330 xxx xxx. (0330 is time group in GMT)

    valid time range is 2100-0300 utc.
    how to validate time and highlight the liine 4 as it exceed the time range.

    million thanks in advance.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101

    Re: how to validate time hhmm

    Code:
                string time = Console.ReadLine();
    
                byte hour = byte.Parse(time[0].ToString() + time[1].ToString());
                byte mins = byte.Parse(time[2].ToString() + time[3].ToString());
                if (hour == 21 || hour == 22 || hour == 23 || hour == 00 || hour == 01 || hour == 02 || hour == 03)
                {
                    if (mins < 60 && mins >= 0)
                    {
                        if (hour == 03 && mins > 00)
                            Console.WriteLine("Invalid");
                        else if (hour == 21 && mins < 01)
                            Console.WriteLine("Invalid");
                        else
                            Console.WriteLine("Valid");
                    }
                    else
                        Console.WriteLine("Invalid");
                }
                else
                    Console.WriteLine("Invalid");
                
                Console.ReadLine();
    This code works... it's self explanatory.
    There might be (which I am like 99% sure there is) a more compact version of this code.. but hey.. this one works!

    Made it in like 2 mins... should be beginner stuff...

  4. #3
    zabbath is offline Newbie
    Join Date
    Jan 2009
    Posts
    3
    Rep Power
    0

    Smile Re: how to validate time hhmm

    thank you very much.

  5. #4
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101

    Re: how to validate time hhmm

    You are welcome. Glad to help you... if you have any more questions just ask

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Validation - How can I validate a form with PHP
    By John Ugwuozor in forum PHP Development
    Replies: 2
    Last Post: 08-04-2010, 10:20 AM
  2. How do you validate an ADOtable?
    By 2710 in forum Pascal and Delphi
    Replies: 30
    Last Post: 03-17-2010, 10:01 PM
  3. PHP: Validate Email Address
    By Jordan in forum PHP Tutorials
    Replies: 26
    Last Post: 05-22-2008, 10:15 AM
  4. How to validate prospects?
    By BAII in forum General Programming
    Replies: 2
    Last Post: 05-05-2008, 12:49 PM
  5. Validate IP address in Python
    By reachpradeep in forum Python
    Replies: 1
    Last Post: 03-03-2007, 01:11 PM

Tags for this Thread

Bookmarks

Posting Permissions

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