Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I subtract a second from a DateTime in Windows Phone 7?

I am trying to subtract a second from time value in a time picker. I found the code to add a second to the picker value, but I couldn't figure out how to subtract.

How should I go about doing it?

private static void CreateAlarm(DateTime time, string title)
{
    var alarm = new Alarm(title)
    {
        Content = "You have a meeting with your team now.",
        BeginTime = time.AddSeconds(10),
    };
}

private void SetAlarm_Click(object sender, RoutedEventArgs e)
{
    CreateAlarm(Convert.ToDateTime(timePicker1.ValueString), textBox1.Text);
}
like image 472
beny lim Avatar asked Aug 06 '11 05:08

beny lim


People also ask

How do you subtract DateTime?

Subtract(DateTime) This method is used to subtract the specified date and time from this instance. Syntax: public TimeSpan Subtract (DateTime value); Return Value: This method returns a time interval that is equal to the date and time represented by this instance minus the date and time represented by value.

How to minus two DateTime?

DateTime. Subtract(TimeSpan) returns a new DateTime that subtracts the specified time interval (TimeSpan value) from the current instance. The Subtract() method subtract TimeSpan object from the DateTime object.

How to minus minutes from DateTime in C#?

Add(new TimeSpan(0,-45,0)); Or you can also use the DateTime. Subtract(TimeSpan) method analogously.


1 Answers

Just add a minus sign:

EndTime = time.AddSeconds(-10)
like image 61
Mike Diaz Avatar answered Sep 24 '22 04:09

Mike Diaz