Solved

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

Posted on 2006-11-01
3
195 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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