Hello Everyone,
How can I compare time in C#.
I have to write that if the current time is less than 9:30 am then exit the
program.
How can i do this programmatically. Right now I am trying to do the code
below, but it doen't work
DateTime dtTime = DateTime.Now;
DateTime timeLimit = new DateTime(dtTime.Year,dtTime.Month, dtTime.Day,
9,30,0);
if ( dtTime < timeLimit)
return;
else
{
}
Thanks. 5 5790
DateTime dt = DateTime.Now;
if( dt.Hour < 9 || ( dt.Hour == 9 && dt.Minute < 30 ) )
{
}
else
{
}
"Vinki" <Vi***@discussions.microsoft.comwrote in message
news:54**********************************@microsof t.com...
Hello Everyone,
How can I compare time in C#.
I have to write that if the current time is less than 9:30 am then exit
the
program.
How can i do this programmatically. Right now I am trying to do the code
below, but it doen't work
DateTime dtTime = DateTime.Now;
DateTime timeLimit = new DateTime(dtTime.Year,dtTime.Month, dtTime.Day,
9,30,0);
if ( dtTime < timeLimit)
return;
else
{
}
Thanks.
Vinki wrote:
Hello Everyone,
How can I compare time in C#.
I have to write that if the current time is less than 9:30 am then exit the
program.
How can i do this programmatically. Right now I am trying to do the code
below, but it doen't work
DateTime dtTime = DateTime.Now;
DateTime timeLimit = new DateTime(dtTime.Year,dtTime.Month, dtTime.Day,
9,30,0);
if ( dtTime < timeLimit)
return;
else
{
}
Thanks.
Standard question #1:
What do you mean by "not working"?
Your code is just fine. I even tried it to be absolutely sure, and it
works exactly as expected.
--
Göran Andersson
_____ http://www.guffa.com
On Sat, 24 Feb 2007 01:59:08 +0100, Göran Andersson <gu***@guffa.comwrote:
>Vinki wrote:
>Hello Everyone,
How can I compare time in C#. I have to write that if the current time is less than 9:30 am then exit the program.
How can i do this programmatically. Right now I am trying to do the code below, but it doen't work
DateTime dtTime = DateTime.Now; DateTime timeLimit = new DateTime(dtTime.Year,dtTime.Month, dtTime.Day, 9,30,0);
if ( dtTime < timeLimit) return; else {
}
Thanks. Standard question #1: What do you mean by "not working"?
Your code is just fine. I even tried it to be absolutely sure, and it works exactly as expected.
I agree>
I think perhaps the problem is that when you do something like that in the
Form.Load event you cannot just say return as you did in the sample you gave us.
Doing so will only abort the load event. It will not close the form
(Application).
I think what you want is below:
if ( dtTime < timeLimit)
Application.Exit();
else
{
}
Good luck with your project,
Otis Mukinfus http://www.otismukinfus.com http://www.arltex.com http://www.tomchilders.com http://www.n5ge.com
You could also put the check in the Main method, before the application is created.
On Sat, 24 Feb 2007 14:23:34 +0100, Otis Mukinfus <ph******************@phoney.comwrote:
On Sat, 24 Feb 2007 01:59:08 +0100, Göran Andersson <gu***@guffa.comwrote:
>Vinki wrote:
>>Hello Everyone,
How can I compare time in C#. I have to write that if the current time is less than 9:30 am then exit the program.
How can i do this programmatically. Right now I am trying to do the code below, but it doen't work
DateTime dtTime = DateTime.Now; DateTime timeLimit = new DateTime(dtTime.Year,dtTime.Month, dtTime.Day, 9,30,0);
if ( dtTime < timeLimit) return; else {
}
Thanks. Standard question #1: What do you mean by "not working"?
Your code is just fine. I even tried it to be absolutely sure, and it works exactly as expected.
I agree>
I think perhaps the problem is that when you do something like that in the
Form.Load event you cannot just say return as you did in the sample you gave us.
Doing so will only abort the load event. It will not close the form
(Application).
I think what you want is below:
if ( dtTime < timeLimit)
Application.Exit();
else
{
}
Good luck with your project,
Otis Mukinfus
http://www.otismukinfus.com http://www.arltex.com http://www.tomchilders.com http://www.n5ge.com
--
Happy coding!
Morten Wennevik [C# MVP]
On Sat, 24 Feb 2007 17:31:12 +0100, "Morten Wennevik [C# MVP]"
<Mo************@hotmail.comwrote:
>You could also put the check in the Main method, before the application is created.
Yes and that's even better!
>
On Sat, 24 Feb 2007 14:23:34 +0100, Otis Mukinfus <ph******************@phoney.comwrote:
>On Sat, 24 Feb 2007 01:59:08 +0100, Göran Andersson <gu***@guffa.comwrote:
>>Vinki wrote: Hello Everyone,
How can I compare time in C#. I have to write that if the current time is less than 9:30 am then exit the program.
How can i do this programmatically. Right now I am trying to do the code below, but it doen't work
DateTime dtTime = DateTime.Now; DateTime timeLimit = new DateTime(dtTime.Year,dtTime.Month, dtTime.Day, 9,30,0);
if ( dtTime < timeLimit) return; else {
}
Thanks.
Standard question #1: What do you mean by "not working"?
Your code is just fine. I even tried it to be absolutely sure, and it works exactly as expected.
I agree>
I think perhaps the problem is that when you do something like that in the Form.Load event you cannot just say return as you did in the sample you gave us. Doing so will only abort the load event. It will not close the form (Application).
I think what you want is below:
if ( dtTime < timeLimit) Application.Exit(); else {
}
Good luck with your project,
Otis Mukinfus
http://www.otismukinfus.com http://www.arltex.com http://www.tomchilders.com http://www.n5ge.com
Good luck with your project,
Otis Mukinfus http://www.otismukinfus.com http://www.arltex.com http://www.tomchilders.com http://www.n5ge.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Marcus |
last post by:
I am having some problems with trying to perform calculations on time
fields. Say I have a start time and an end time, 1:00:00 and 2:30:00
(on a 24 hour scale, not 12). I want to find the...
|
by: Florian Lindner |
last post by:
Hello,
I've read the chapter in the Python documentation, but I'm interested in a a
more in-depth comparision. Especially regarding how pythonic it is and how
well it performs and looks under...
|
by: John Black |
last post by:
Hi,
In using find_if() you need to name a comparision function which
normally is a static function, but sometimes it is really inconvinient
for this, let's take this example,
class MyClass{...
|
by: Ashwin Kambli |
last post by:
Hi,
I am doing a study on the performance comparision of C# and Java. Links to
any articles on this topic will be greatly appreciated.
Thanking you,
Ashwin
|
by: HL |
last post by:
I am using VS 2005 Beta - C#
Problem: The Timer fires a few milliseconds before the actual Due-Time
Let's say a timer is created in the following manner:
System.Threading.Timer m_timer = null;...
|
by: kd |
last post by:
Hi All,
How to perform case-insensitive comparision of strings?
Would there be some kind of an indicator, which when set to true, would
allow case-insenitive comparision of strings using...
|
by: I Don't Like Spam |
last post by:
I know this should be simple but I can't find it.
Dim A as new object
Dim B as object
B = A
Do Bunch of stuff
Check if B still = A
|
by: nirav.lulla |
last post by:
I have been given the task to come up with Requirements, Comparision
and Migration document from Shadow Direct to DB2 Connect. I am very new
much to all this, but kind of know a little bit about...
|
by: abctech |
last post by:
I have an Html page, user enters a Date (dd-mm-yyyy) here. There's a servlet connected in the backend for processing this submitted information, it must have a method to compare this entered date...
|
by: =?Utf-8?B?UGF1bA==?= |
last post by:
Hi I am trying to compare just the time portion of two variables that are of
date time part. For example I have
dtdate1= 2/2/07 10:00:00
dtdate2=3/4/07 9:00:00
so for the comparision I would...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |