Solved

Past a certain time of day. C#

Posted on 2011-03-25
3
385 Views
Last Modified: 2012-05-11
What C# code can I use to determine if it's past a certain time of day?
Example, I'm getting a string type that contains 4:30pm in military time....

"16:30"
0
Comment
Question by:silentthread2k
3 Comments
 
LVL 22

Accepted Solution

by:
p_davis earned 250 total points
ID: 35216867
TimeSpan.Parse(yourString) > DateTime.Now.TimeOfDay

although implementing tryparse would be more fool proof way to code
0
 
LVL 15

Assisted Solution

by:angus_young_acdc
angus_young_acdc earned 250 total points
ID: 35217064
The following code will make sure the time is in the correct format
string time = "4:30pm";
            DateTime dt = Convert.ToDateTime(Convert.ToDateTime(time).ToString("hh:mm"));

            if (dt.TimeOfDay > DateTime.Now.TimeOfDay)
            {
                // do something
            }

Open in new window

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35217430
Just guessing....but he probably wants to know if the CURRENT time is past the time in the string?

If so, switch the IF statement order...   =)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question