Solved

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

813 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

14 Experts available now in Live!

Get 1:1 Help Now