## explaining the output of datevec

on 26 May 2012

### Oleg Komarov (view profile)

HI all,

I have the following code

```   numdays = datenum({'02/11/08'},'dd/mm/yy') - datenum({'09/10/11'},'dd/mm/yy')
numweeks28 = numdays / (7*4)
numweeks28vec = datevec(numweeks28)```

that produces numdays =

`       -1071`

numweeks28 =

```-38.2500
```

numweek28svec =

`    -1    11    22    18     0     0`

It is not clear to m e what -1 11 22 18 0 0 of numweek28svec means? For example, what is -1,11,...?

Thanks

## Products

No products are associated with this question.

### Oleg Komarov (view profile)

on 26 May 2012

The 4th line of datevec() syntax is:

```[Y, M, D, H, MN, S] = datevec(...)
```

Where it's self-explanatory that

```-1    11    22    18     0     0
Y     M     D     H    MN     S
```

Now, the fact that you're doing SomeDate - DateInFuture, determines the negative sign.

Thus,

```datevec(-38.25)
```

says which Year, Month, etc.. is that serial date.

For intuition, supose you are 3 days Before Christ. Datevec would say you're in the Year before BC (thus -1), in the 12th month, 22nd day etc... (assuming he was born the 25th Dec).

antonet

### antonet (view profile)

on 26 May 2012

thank you very much

### per isakson (view profile)

on 26 May 2012

datevec interprets a double as a serial date number.

numdays = -1071 says that the first date is 1071 days before the latter.

numweek28svec = datevec( -38.2500 ) should return something 38.25 days before something

minus 1 year plus 11 month plus 22 days plus 18 hours will add up in something like -38.25 days

However, many Matlab releases before now datevec didn't handle this kind of calculation.

One year is that a year with a leap day or not. IMO one should NOT use datevec like this.

antonet

### antonet (view profile)

on 26 May 2012

thank you per isakson

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi