Solved

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

Posted on 2006-11-01
3
190 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
3 Comments
 
LVL 13

Accepted Solution

by:
joechina earned 250 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 250 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

12 Experts available now in Live!

Get 1:1 Help Now