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

x
?
Solved

500pts: Is Time > 08:15 in the morning?

Posted on 2006-11-01
3
Medium Priority
?
199 Views
Last Modified: 2010-04-16
Hi there,

Can anybody tell me how to find out if the current time using NOW is greater than a certain time

if ( DateTime.Now.AddMinutes(-5).ToShortTimeString() >= thisMarket.OpenTime.ToShortTimeString()  )

 thisMarket.OpenTime is DateTime and contains 08:15

I need for it to return true if it is anywhere from 08:10 (notice the -5) to 00:00

I hope someone can help

Thanks in advance

ian

0
Comment
Question by:ianinspain
[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 13

Accepted Solution

by:
joechina earned 1000 total points
ID: 17852790
double diff = thisMarket.OpenTime.TimeOfDay.TotalSeconds - DateTime.Now.TimeOfDay.TotalSeconds;

(diff > 0 and diff <= 60*5)   returns true if the time is between 8:10 to 8:15

(diff > 0 and diff > 60*5) returns true if the time is between 0:00 to 8:10
0
 
LVL 20

Assisted Solution

by:TheAvenger
TheAvenger earned 1000 total points
ID: 17852948
Don't compare strings - this is a source of errors. You can just compare the times. Also you need to add 5, not subtract them, if you are searching for times between 8:10 and 00:00

if (DateTime.Now.AddMinutes(5).TimeOfDay >= thisMarket.OpenTime.TimeOfDay)
  // Do whatever you want
0
 

Author Comment

by:ianinspain
ID: 17853188
thanks both!

Much appreciated

Ian
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 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