Solved

Past a certain time of day. C#

Posted on 2011-03-25
3
382 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A short article about problems I had with the new location API and permissions in Marshmallow
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

747 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now