Got Questions? Get Answers.
Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
datenum works only sometimes for yyyymmdd format

Subject: datenum works only sometimes for yyyymmdd format

From: Andrew O'Connor

Date: 13 Jul, 2011 08:33:07

Message: 1 of 4

G'Day All, I'm having trouble with datenum. I've been using it for sometime to convert a cell array of strings to a date value. However only today it seems to work sometime and not others. For example the following is an extract from my command wondow:

datenum('20070614', 'yyyymmdd')
??? Error using ==> datenum at 178
DATENUM failed.

Caused by:
    Error using ==> dtstr2dtnummx
    Failed on converting date string to date number.

------------------------------
And then after 4 more commands of playing around I get this:

datenum('20070614', 'yyyymmdd')

ans =

      733207

---------------------------------------
The commands I did in between the command which worked and the command which didn't were:
  datenum('20070614', 'yyyymmdd')
??? Error using ==> datenum at 178
DATENUM failed.

Caused by:
    Error using ==> dtstr2dtnummx
    Failed on converting date string to date number.
 
>> datenum('20070614')
??? Error using ==> datenum at 178
DATENUM failed.

Caused by:
    Error using ==> datevec at 280
    Cannot parse date 20070614.
 
>> datenum('2007-06-14')

ans =

      733207

>> datenum('20070614', 'yyyyMMdd')
??? Error using ==> datenum at 178
DATENUM failed.

Caused by:
    Error using ==> dtstr2dtnummx
    Failed on converting date string to date number.
 
>> datenum('20070614', 'yyyymmdd')

ans =

      733207


Why do I get this random behaviour of working and not?


 

Subject: datenum works only sometimes for yyyymmdd format

From: George Coles

Date: 5 Oct, 2011 13:36:29

Message: 2 of 4

"Andrew O'Connor" <AndrewNOConnor@gmail.com> wrote in message <ivjl83$9us$1@newscl01ah.mathworks.com>...
> G'Day All, I'm having trouble with datenum. I've been using it for sometime to convert a cell array of strings to a date value. However only today it seems to work sometime and not others. For example the following is an extract from my command wondow:
>
> datenum('20070614', 'yyyymmdd')
> ??? Error using ==> datenum at 178
> DATENUM failed.
>
> Caused by:
> Error using ==> dtstr2dtnummx
> Failed on converting date string to date number.
>
> ------------------------------
> And then after 4 more commands of playing around I get this:
>
> datenum('20070614', 'yyyymmdd')
>
> ans =
>
> 733207
>
> ---------------------------------------
> The commands I did in between the command which worked and the command which didn't were:
> datenum('20070614', 'yyyymmdd')
> ??? Error using ==> datenum at 178
> DATENUM failed.
>
> Caused by:
> Error using ==> dtstr2dtnummx
> Failed on converting date string to date number.
>
> >> datenum('20070614')
> ??? Error using ==> datenum at 178
> DATENUM failed.
>
> Caused by:
> Error using ==> datevec at 280
> Cannot parse date 20070614.
>
> >> datenum('2007-06-14')
>
> ans =
>
> 733207
>
> >> datenum('20070614', 'yyyyMMdd')
> ??? Error using ==> datenum at 178
> DATENUM failed.
>
> Caused by:
> Error using ==> dtstr2dtnummx
> Failed on converting date string to date number.
>
> >> datenum('20070614', 'yyyymmdd')
>
> ans =
>
> 733207
>
>
> Why do I get this random behaviour of working and not?
>
>
>

I am having the same trouble.

Subject: datenum works only sometimes for yyyymmdd format

From: ade77

Date: 6 Oct, 2011 13:18:10

Message: 3 of 4

I guess ur problem is what u are typing on the command prompt. I tried it 100 times with no error.
However, when I type the same, and I leave a space as in 'yyyymmdd ', then I get that error.

when u run the command,
 datenum('20070614', 'yyyymmdd'), and it works for u, repeat the command by using the upper arrow on the keyboard, u will see u will not get the error again.

My guess is u are typing it in the command window, and allowing a space in the format area(yyyymmdd).

... and it could be something else. Let me know how ur investigation goes.

Subject: datenum works only sometimes for yyyymmdd format

From: Andrew O'Connor

Date: 6 Oct, 2011 14:06:26

Message: 4 of 4

G'Day ade77, I was using the up arrow to repeat the command and I still had the problem.

Having had the problem for a number of months now I've found the following:
- I believe it to be a memory problem as it only occurs when I have large amounts of data loaded into the variables.
- The trouble maker is the mex file, datenummx.
- I also found a bunch of other people who had the same problem here:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/287922#841230


Given the fact that all my dates were in a cell array, the solution I used was:

csDates = {'20070614'}

dDatesNum = datenum(cellfun(@(x) {[x(1:4) '-' x(5:6) '-' x(7:8)]}, csDates), 29);

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us