1

I need help with DateTime.
I want my application to check if DateTime end is up and gives me a messagebox.
How do I write that?
Code:

private void listjob()
{
    DispatcherTimer dispatcherTimer = new DispatcherTimer();
    dispatcherTimer.Tick += new EventHandler(listjob3_Tick);
    dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1);
    dispatcherTimer.Start();
}
private void listjob3_Tick(object sender, EventArgs e)
{
    if (listbox3job())
    {
        DateTime? start = DateTimePicker1.Value;
        DateTime? end = DateTimePicker2.Value;
        DateTime now = DateTime.Now;
        if (?) // here is what I want it to check if end time is started
        {
           Xceed.Wpf.Toolkit.MessageBox.Show("End Time started");
           DispatcherTimer timer = (DispatcherTimer)sender;
           timer.Stop();
           timer = null;
        }
    }
}
Sneakybastardd
  • 288
  • 1
  • 5
  • 17
  • The Application is WPF modified with compatible DateTimePicker. – Sneakybastardd Apr 17 '13 at 14:06
  • I know you're just starting out in software, but you need to start using better variable and method names right now. `listbox3job` is no good, even for a prototype. `listjob3` as a control name is no good either. Sorry to be picky, but pick up the habit now before it's too late – Kieren Johnstone Apr 17 '13 at 14:11
  • @KierenJohnstone Any suggestions for better names? :) – Sneakybastardd Apr 17 '13 at 14:17
  • Whatever they represent - is it a list of pending calculation jobs? Active print jobs? Job titles to be added to a list? – Kieren Johnstone Apr 17 '13 at 16:00

2 Answers2

2

Unless I'm grossly misunderstanding what you want:

if (now >= end)

or in other words, if the current time is greater than or equal to the end time. If you just wanted to know if the current time is past the end time then:

if (now > end)
Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
0
if(end<= now)

It's just like that. If you have some issue with the type, use ToShortDateString() or other properties

Alice
  • 313
  • 2
  • 5
  • 16
  • I don't think the `ToShortDateString()` is necessary. `DateTime`s don't have a format, only their string representations do. – Nolonar Apr 17 '13 at 14:11