---
title: "Timer not detecting when input matches DateTime.Now"  
description: "Timer not detecting when input matches DateTime.Now"  
author: "Royce Roy"  
published: 2013-12-23  
updated: 2013-12-23  
canonical: https://www.mindstick.com/forum/1831/timer-not-detecting-when-input-matches-datetime-now  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Timer not detecting when input matches DateTime.Now

I have a [timer](https://www.mindstick.com/articles/52/creating-timer-at-runtime-in-c-sharp-dot-net) on my form with an interval of 1000 (1 [second](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society)). I am allowing the user to [input](https://www.mindstick.com/forum/159209/how-can-i-read-convert-an-input-stream-into-a-string-in-java) a time via three comboboxes. The time they input is then converted to the [DateTime](https://www.mindstick.com/forum/12949/how-to-validate-if-a-datetime-field-is-not-null-empty) format. Finally, the timer checks every tick if the input time [equals](https://www.mindstick.com/interview/33895/difference-between-and-equals-method-in-c-sharp) DateTime.Now. The [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is that it's not working.

Say I set the [alarm](https://www.mindstick.com/articles/23246/best-personal-alarm-choices-nowadays) to 9:00:00 PM when it's 8:59:50 PM. I [click](https://www.mindstick.com/articles/12423/social-login-magento-2-one-click-to-register-social) Start and wait ten seconds for the alarm to go off, but it [never](https://yourviews.mindstick.com/view/290/zoos-prisons-for-beings-who-have-never-committed-a-crime) does. When [debugging](https://www.mindstick.com/blog/393/javascript-debugging) the code, both numbers are the same, meaning that it should fire, but it doesn't.

## Here's my code:

```
private void tmrAlarm_Tick(object sender, EventArgs e) {    DateTime alarmTime = Convert.ToDateTime(statusAlarm.Text); // say statusAlarm.Text is 9:00:00 PM    if(alarmTime == DateTime.Now) {        MessageBox.Show("bzzt");    }}
```

## Replies

### Reply by Pravesh Singh

Hi Royce,

You could also use

DateTime.Now.ToShortTimeString() method for checking equality


---

Original Source: https://www.mindstick.com/forum/1831/timer-not-detecting-when-input-matches-datetime-now

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
