dateTimePicker = DateTime.Now & "Time"

Whats the most efficient way to :

Fire an event on a certain Day, Date and Time...

Im using a dateTimePicker...for the day, date.

Time is in comboboxes, start and end. ("1 AM")

Just started...formatting is getting crazy...there must be an easier way.




Answer this question

dateTimePicker = DateTime.Now & "Time"

  • erodcav

    I think the best way would be to use the Substract method of DateTime to find out the TimeSpan between the 2 dates. Then with the TotalMilliseconds property you know in how many ms you need to fire your event. From there you can use a Timer (System.Timers) to fire an event in xxxx ms.

  • justinmagaram

    Set the Format property to Long and use Value to read DateTime type of selected date.
    Also posible is to use MaskedTextBox control.

  • jamesIEDOTNET

    One thing you'll probably want to keep in mind when using a timer to check if the date/time equals the selected date time is that your timer may not fire at the exact date/time the user has chosen.  Most likely you will be firing your timer every few minutes/seconds/milliseconds and might miss the percise time selected.

    So, you would want to make a comparison of the DateTime.Now value versus the selected date/time and see if the timer has fired within an acceptable tolerance of the selected date/time.  I believe the TimeSpan structure would accomodate your needs in this area.

     


  • NET PR

    I have the "event" taken care of.

    Need something like:

    If(dateTimePicker.Now == DateTime.Now)

    ////Fire event

    Just not familar with DTP...regarding Time etc.



  • AnneF

    date time picker is to determine which day and which time just a UI for the user, but what fire the event is the code that you will write

    the best thing for that i guess is using timer

    hope this helps



  • dateTimePicker = DateTime.Now & "Time"