# How to substract the minute?

7316

I want to substract the minute value as 10:

eg: if i give 00 means it should consider 50, 50 means 40,etc...

tried following code. but it seems wrong. can you suggest exact idea to substract the minute?

```extern int newsDateMinute = 30;
newsDateMinute -= 10;```
247

sheriffonline:

I want to substract the minute value as 10:

eg: if i give 00 means it should consider 50, 50 means 40,etc...

tried following code. but it seems wrong. can you suggest exact idea to substract the minute?

what is the problem?

`newsDateMinute = newsDateMinute-10;`

or you get -10 when the minute is 00?

`if (newsDateMinute==-10) { newsDateMinute=50; }`

or at the beginning add this line:

`if (newsDateMinute==0) { newsDateMinute=60; }`
17410

sheriffonline:

I want to substract the minute value as 10:

eg: if i give 00 means it should consider 50, 50 means 40,etc...

tried following code. but it seems wrong. can you suggest exact idea to substract the minute?

If you want to avoid issue and complications with dates and time use datetimes . . . then to subtract 10 minutes you subtract 10 * 60
369

sheriffonline:

I want to substract the minute value as 10:

eg: if i give 00 means it should consider 50, 50 means 40,etc...

tried following code. but it seems wrong. can you suggest exact idea to substract the minute?

First, I agree with RaptorUK. Using datetime type variable would be better and probably easier.

Second, regarding the code you posted, if you review newDateMinute after you've changed it to determine whether it is negative and, if so, add 60, that (i think) should get you to what you are looking for.

```extern int newsDateMinute = 30;

newsDateMinute -= 10;
if (newsDateMinute < 0)
newsDateMinute += 60;```

So, if newsDateMinute = 30 and you subtract 50, that gives you -20; then if you add 60, newsDateMinute becomes 40. But remember: if you have a variable that stores the hour (such as newsDateHour), you must reduce that variable by 1 each time the above subtraction produces a negative result. And you may have to do that with the variable(s) which store the day, month, and year if they are stored separately, rather than in a datetime. This example illustrates why using a datetime variable would be better, possibly more accurate, and probably easier for you to maintain, as RaptorUK has suggested.

7316

Thanks guys. got it and works fine....