problem with datenum: it does not return the same number for the same date

1 view (last 30 days)
Hi everybody,
I have a problem with datenum. I have some operations to do on dates. The problem is the following one: for the same date, datenum does not return the same number... that's a problem. My comands:
dnum = datenum(Date(1:n),'dd/mm/yyyy');
dnumCRB = datenum(DateCRB(1:n3),'dd/mm/yyyy');
whos Date DateCRB
Name Size Bytes Class Attributes
Date 1756x1 231572 cell
DateCRB 1756x1 230572 cell
[Date(1:10) DateCRB(1:10)]
ans =
'09/10/2008' '09/10/2008'
'10/10/2008' '10/10/2008'
'13/10/2008' '13/10/2008'
'14/10/2008' '14/10/2008'
'15/10/2008' '15/10/2008'
'16/10/2008' '16/10/2008'
'17/10/2008' '17/10/2008'
'20/10/2008' '20/10/2008'
'21/10/2008' '21/10/2008'
'22/10/2008' '22/10/2008'
[dnum(1:10) dnumCRB(1:10)]
ans =
733661 733661
733662 733690
733663 733691
733666 733694
733667 733695
733668 733696
733669 733697
733670 733698
733673 733701
733674 733702
Do you know what's happened here?
Thank you very much for your help,
Best,
Thomas

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 3 Jul 2015
Edited: Azzi Abdelmalek on 3 Jul 2015
If we check this, there is no problem
s={'09/10/2008' '09/10/2008'
'10/10/2008' '10/10/2008'
'13/10/2008' '13/10/2008'
'14/10/2008' '14/10/2008'
'15/10/2008' '15/10/2008'
'16/10/2008' '16/10/2008'
'17/10/2008' '17/10/2008'
'20/10/2008' '20/10/2008'
'21/10/2008' '21/10/2008'
'22/10/2008' '22/10/2008'}
d1=s(:,1)
d2=s(:,2)
dnum=datenum(d1,'dd/mm/yyyy')
dnumCRB=datenum(d2,'dd/ mm/ yyyy ')
[dnum dnumCRB]
We can check the problem, if you attach your data file
  2 Comments
Thomas
Thomas on 4 Jul 2015
Edited: Thomas on 4 Jul 2015
Thanks a lot for you answer. I attach my data file. The problem in fact is (i think) that the format dd/mm/yyyy is not recognize. Am I right? EDIT: Hm, no, my guess was not correct. I have tried with the format mm/dd/yyyy and it fails again...
Campion Loong
Campion Loong on 6 Jul 2015
Thomas, You file does not look entirely comma-separated. Some fields have numbers attached followed by semicolons.
Will you also post the code you use to import these to generate the 'Date' & 'DateCRB' variables in the first place?

Sign in to comment.

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!