Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Past a certain time of day. C#

Posted on 2011-03-25
3
Medium Priority
?
392 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 1000 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 1000 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 86

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Introduction to Processes
Screencast - Getting to Know the Pipeline

971 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