From: guyz Smarty on
Hi all,

I don't know if it is too basic problem or not. but it is really annoying.

I am trying to execute following command:

datenum('02 01 2008','dd mm yyyy')

But unfortunately, I get following error message:

>> datenum('02 01 2008','dd mm yyyy')
??? Error using ==> datenum at 182
DATENUM failed.

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

Ans now comes the strange thing. If I run the same command again, I get the correct result this time. But, I get the error message again if I try to run the same command.

What I mean to say is that the command runs for me (or I get the correct result) every alternate times. I will paste the command window lines here to make things clearer.

=====================================

>> datenum('02 01 2008','dd mm yyyy')
ans =
733409

>> datenum('02 01 2008','dd mm yyyy')
??? Error using ==> datenum at 182
DATENUM failed.
Caused by:
Error using ==> dtstr2dtnummx
Failed on converting date string to date number.

>> datenum('02 01 2008','dd mm yyyy')
ans =
733409

>> datenum('02 01 2008','dd mm yyyy')
??? Error using ==> datenum at 182
DATENUM failed.
Caused by:
Error using ==> dtstr2dtnummx
Failed on converting date string to date number.

>> datenum('02 01 2008','dd mm yyyy')
ans =
733409
=====================================

Any help would be appreciated.

Thanks.
From: us on
"guyz Smarty" <guyz.smarty(a)gmail.com> wrote in message <i2ncks$2p7$1(a)fred.mathworks.com>...
> Hi all,
>
> I don't know if it is too basic problem or not. but it is really annoying.
>
> I am trying to execute following command:
>
> datenum('02 01 2008','dd mm yyyy')
>
> But unfortunately, I get following error message:
>
> >> datenum('02 01 2008','dd mm yyyy')
> ??? Error using ==> datenum at 182
> DATENUM failed.
>
> Caused by:
> Error using ==> dtstr2dtnummx
> Failed on converting date string to date number.
>
> Ans now comes the strange thing. If I run the same command again, I get the correct result this time. But, I get the error message again if I try to run the same command.
>
> What I mean to say is that the command runs for me (or I get the correct result) every alternate times. I will paste the command window lines here to make things clearer.
>
> =====================================
>
> >> datenum('02 01 2008','dd mm yyyy')
> ans =
> 733409
>
> >> datenum('02 01 2008','dd mm yyyy')
> ??? Error using ==> datenum at 182
> DATENUM failed.
> Caused by:
> Error using ==> dtstr2dtnummx
> Failed on converting date string to date number.
>
> >> datenum('02 01 2008','dd mm yyyy')
> ans =
> 733409
>
> >> datenum('02 01 2008','dd mm yyyy')
> ??? Error using ==> datenum at 182
> DATENUM failed.
> Caused by:
> Error using ==> dtstr2dtnummx
> Failed on converting date string to date number.
>
> >> datenum('02 01 2008','dd mm yyyy')
> ans =
> 733409
> =====================================
>
> Any help would be appreciated.
>
> Thanks.

now THAT IS unheard-of...
- are you telling the whole story(?)...
- which ML ver do you have(?)...

here (r2010a), this runs - forever

for i=1:100000
r=datenum('02 01 2008','dd mm yyyy');
end
disp(r);
% 733409

us
From: Oleg Komarov on
"us " <us(a)neurol.unizh.ch> wrote in message <i2ne0k$3ut$1(a)fred.mathworks.com>...
> "guyz Smarty" <guyz.smarty(a)gmail.com> wrote in message <i2ncks$2p7$1(a)fred.mathworks.com>...
> > Hi all,
> >
> > I don't know if it is too basic problem or not. but it is really annoying.
> >
> > I am trying to execute following command:
> >
> > datenum('02 01 2008','dd mm yyyy')
> >
> > But unfortunately, I get following error message:
> >
> > >> datenum('02 01 2008','dd mm yyyy')
> > ??? Error using ==> datenum at 182
> > DATENUM failed.
> >
> > Caused by:
> > Error using ==> dtstr2dtnummx
> > Failed on converting date string to date number.
> >
> > Ans now comes the strange thing. If I run the same command again, I get the correct result this time. But, I get the error message again if I try to run the same command.
> >
> > What I mean to say is that the command runs for me (or I get the correct result) every alternate times. I will paste the command window lines here to make things clearer.
> >
> > =====================================
> >
> > >> datenum('02 01 2008','dd mm yyyy')
> > ans =
> > 733409
> >
> > >> datenum('02 01 2008','dd mm yyyy')
> > ??? Error using ==> datenum at 182
> > DATENUM failed.
> > Caused by:
> > Error using ==> dtstr2dtnummx
> > Failed on converting date string to date number.
> >
> > >> datenum('02 01 2008','dd mm yyyy')
> > ans =
> > 733409
> >
> > >> datenum('02 01 2008','dd mm yyyy')
> > ??? Error using ==> datenum at 182
> > DATENUM failed.
> > Caused by:
> > Error using ==> dtstr2dtnummx
> > Failed on converting date string to date number.
> >
> > >> datenum('02 01 2008','dd mm yyyy')
> > ans =
> > 733409
> > =====================================
> >
> > Any help would be appreciated.
> >
> > Thanks.
>
> now THAT IS unheard-of...
> - are you telling the whole story(?)...
> - which ML ver do you have(?)...
>
> here (r2010a), this runs - forever
>
> for i=1:100000
> r=datenum('02 01 2008','dd mm yyyy');
> end
> disp(r);
> % 733409
>
> us

I had the same exact problem and posted to technical support but I couldn't reproduce the problem...in my case I was using dir (which returns a field called 'datenum'). No solution was found and I didn't encounter the problem when using listed date formats.

Oleg
From: us on
"Oleg Komarov"
> I had the same exact problem and posted to technical support but I couldn't reproduce the problem...in my case I was using dir (which returns a field called 'datenum'). No solution was found and I didn't encounter the problem when using listed date formats.
>
> Oleg

yes...
because:

% note: i assume you meant to say ...which returns a field called 'date'...
d=dir(which('unique'))
%{
name: 'unique.m'
date: '23-Sep-2009 18:09:48'
bytes: 11269
isdir: 0
datenum: 7.3404e+005
%}
% and
datenum(d.date,'dd mm yyyy'); % <- or: datenum(d.date,'dd-mm-yyyy')
%{
??? Error using ==> datenum at 182
DATENUM failed.
Caused by:
Error using ==> dtstr2dtnummx
Failed on converting date string to date number.
%}
% this works
datenum(d.date,'dd-mmm-yyyy HH:MM:SS')-d.datenum
% ans = 0

us
From: Oleg Komarov on
"us " <us(a)neurol.unizh.ch> wrote in message <i2nh38$roh$1(a)fred.mathworks.com>...
> "Oleg Komarov"
> > I had the same exact problem and posted to technical support but I couldn't reproduce the problem...in my case I was using dir (which returns a field called 'datenum'). No solution was found and I didn't encounter the problem when using listed date formats.
> >
> > Oleg
>
> yes...
> because:
>
> % note: i assume you meant to say ...which returns a field called 'date'...
> d=dir(which('unique'))
> %{
> name: 'unique.m'
> date: '23-Sep-2009 18:09:48'
> bytes: 11269
> isdir: 0
> datenum: 7.3404e+005
> %}
> % and
> datenum(d.date,'dd mm yyyy'); % <- or: datenum(d.date,'dd-mm-yyyy')
> %{
> ??? Error using ==> datenum at 182
> DATENUM failed.
> Caused by:
> Error using ==> dtstr2dtnummx
> Failed on converting date string to date number.
> %}
> % this works
> datenum(d.date,'dd-mmm-yyyy HH:MM:SS')-d.datenum
> % ans = 0
>
> us

% note: i assume you meant to say ...which returns a field called 'date'...
datenum

The point is that the error was thrown one time yes and one time no as the OP described.

But as I mentioned I couldn't reproduce this behaviour.
If the OP can post the whole code being executed before he gets the error it would be useful, so that I can compare with my routine too.

Oleg