Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Past a certain time of day. C#

Posted on 2011-03-25
3
Medium Priority
?
390 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

715 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