# what is the precision of a MATLAB datenum?

Asked by Tony on 10 Aug 2012
Latest activity Commented on by Walter Roberson on 10 Aug 2012

I'm trying to timestamp samples at a 20MHz (50 ns period) using datenum, and subsequent timestamps all come out the same when I examine them with datevec (seconds column). Is this just a display issue or am I running up against the precision of datenum?

## Products

No products are associated with this question.

Answer by Jonathan Sullivan on 10 Aug 2012

Well, let's find out.

Let's take a look at the precision of the time "now," converted to seconds

```reference = now;
precision = eps(reference);
precision_seconds = precision*24*3600
```

Looks like about 10 us for an absolute timestamp.

If you want a relative timestamp with a max value of 1 day, we get the following:

```reference = 1;
precision = eps(reference);
precision_seconds = precision*24*3600
```

Now we get a precision of about 0.02 ns.

Walter Roberson on 10 Aug 2012

However,

```>> eps(now) * 24 * 3600
```
```ans =
```
`        1.00582838058472e-05`
Walter Roberson on 10 Aug 2012

Sorry read too quickly.

Answer by the cyclist on 10 Aug 2012
Edited by the cyclist on 10 Aug 2012

The documentation of the datevec() function suggests to me that the precision is 1 millisecond.

A bit of playing around gives that this

```>> datenum('01-00-0000 00:00:00.0001')
```

has a non-zero value, but this

```>> datenum('01-00-0000 00:00:00.00001')
```

is zero, suggesting that maybe it is down around the 100 microseconds, but not 10 microseconds.