Thread Subject: datestr problems

Subject: datestr problems

From: Kelly

Date: 3 Jul, 2007 14:34:09

Message: 1 of 3

I'm seeing some odd behavior with the datestr function. There seems
to be an upper limit on the value of the month number in the input
date vector in order to return the proper string. For example,

datestr([1950 522 15 12 0 0])

ans =

15-Jun-1993 12:00:00

This is the answer that I was expecting. However,

datestr([1950 523 15 12 0 0])

ans =

03-May-0005
06-Jun-0001
15-Jan-0000
12-Jan-0000
00-Jan-0000
00-Jan-0000

The problem seems to occur somewhere in the mex file that does the
major calculations (datevecmx); for some reason it is returning 6 x 1
vectors for the year, month, etc, instead of the scalar values it
should be getting.

Does anyone else see this behavior? Also, does anyone know of a
workaround? I have a lot of data that is given in "months since
1950", and I am looking for an easy way to convert this to
dd-mmm-yyyy strings.

Thanks,
Kelly

Subject: datestr problems

From: Jos

Date: 3 Jul, 2007 14:55:00

Message: 2 of 3

Kelly wrote:
>
>
> I'm seeing some odd behavior with the datestr function. There
> seems
> to be an upper limit on the value of the month number in the input
> date vector in order to return the proper string. For example,
>
> datestr([1950 522 15 12 0 0])
>
> ans =
>
> 15-Jun-1993 12:00:00
>
> This is the answer that I was expecting. However,
>
> datestr([1950 523 15 12 0 0])
>
> ans =
>
> 03-May-0005
> 06-Jun-0001
> 15-Jan-0000
> 12-Jan-0000
> 00-Jan-0000
> 00-Jan-0000
>
> The problem seems to occur somewhere in the mex file that does the
> major calculations (datevecmx); for some reason it is returning 6 x
> 1
> vectors for the year, month, etc, instead of the scalar values it
> should be getting.
>
> Does anyone else see this behavior? Also, does anyone know of a
> workaround? I have a lot of data that is given in "months since
> 1950", and I am looking for an easy way to convert this to
> dd-mmm-yyyy strings.
>
> Thanks,
> Kelly
  
I see the same behavior. A workaround is to convert the date vector
to a datenumber

datestr([1950 523 15 12 0 0])
% --> list of dates

datestr(datenum([1950 523 15 12 0 0]))
% --> 15-Jul-1993 12:00:00

hth
Jos

Subject: datestr problems

From: per isakson

Date: 3 Jul, 2007 16:43:24

Message: 3 of 3

Jos wrote:
>
>
> Kelly wrote:
>>
>>
>> I'm seeing some odd behavior with the datestr function. There
>> seems
>> to be an upper limit on the value of the month number in the
> input
>> date vector in order to return the proper string. For example,
>>
>> datestr([1950 522 15 12 0 0])
>>
>> ans =
>>
>> 15-Jun-1993 12:00:00
>>
>> This is the answer that I was expecting. However,
>>
>> datestr([1950 523 15 12 0 0])
>>
>> ans =
>>
>> 03-May-0005
>> 06-Jun-0001
>> 15-Jan-0000
>> 12-Jan-0000
>> 00-Jan-0000
>> 00-Jan-0000
>>
>> The problem seems to occur somewhere in the mex file that does
> the
>> major calculations (datevecmx); for some reason it is returning
6
> x
>> 1
>> vectors for the year, month, etc, instead of the scalar values
it
>> should be getting.
>>
>> Does anyone else see this behavior? Also, does anyone know of
a
>> workaround? I have a lot of data that is given in "months
since
>> 1950", and I am looking for an easy way to convert this to
>> dd-mmm-yyyy strings.
>>
>> Thanks,
>> Kelly
>
> I see the same behavior. A workaround is to convert the date vector
> to a datenumber
>
> datestr([1950 523 15 12 0 0])
> % --> list of dates
>
> datestr(datenum([1950 523 15 12 0 0]))
> % --> 15-Jul-1993 12:00:00
>
> hth
> Jos
  
The problem is with this boolean expression

all(abs(sum(D,2)-2000)<500) in line 167 of R2006b

The doc says:

A 3- or 6-element vector having a first element within an
approximate range of 500 greater than or less than the current year
is considered by MATLAB to be a date vector. Otherwise, it is
considered to be a vector of serial date numbers.

Someone didn't think about month having large values - I guess. Code
and documentation don't match exactly.

/ per

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com