From: sunram on 18 Jun 2010 05:09 Hi, I am trying to convert a set of numbers yyyymmdd to dd-mm-yyyy. I have tried to use datestr but I think due to the order of my numbers it does not convert it properly. So for example : x = 19610807; d = datestr(x) d = 24-Jul-3692 I would expect 07-Aug-1961. Secondly, how can I get it to display 08 instead of Aug ? Your help is much appreciated.
From: Walter Roberson on 18 Jun 2010 08:44 sunram wrote: > I am trying to convert a set of numbers yyyymmdd to dd-mm-yyyy. > > I have tried to use datestr but I think due to the order of my numbers > it does not convert it properly. > > So for example : > > x = 19610807; > d = datestr(x) > d = 24-Jul-3692 > > I would expect 07-Aug-1961. Numeric dates are expected to be in "serial date format", which is the number of days (and fractions of a day) since 1-jan-0000. datestr(datenum(sprintf('%d',x),'yyyymmdd'),'dd-mm-yyyy') Or more simply, sprintf('%02d-%02d-%04d', mod(x,100), mod(floor(x/100),100), floor(x/10000));
From: sunram on 21 Jun 2010 03:32 Walter Roberson <roberson(a)hushmail.com> wrote in message <4TJSn.83249$HG1.13582(a)newsfe21.iad>... > sunram wrote: > > > I am trying to convert a set of numbers yyyymmdd to dd-mm-yyyy. > > > > I have tried to use datestr but I think due to the order of my numbers > > it does not convert it properly. > > > > So for example : > > > > x = 19610807; > > d = datestr(x) > > d = 24-Jul-3692 > > > > I would expect 07-Aug-1961. > > Numeric dates are expected to be in "serial date format", which is the > number of days (and fractions of a day) since 1-jan-0000. > > datestr(datenum(sprintf('%d',x),'yyyymmdd'),'dd-mm-yyyy') > > Or more simply, > > sprintf('%02d-%02d-%04d', mod(x,100), mod(floor(x/100),100), > floor(x/10000)); Thank you very much! That helps. I try to change a whole column worth of data by doing : date = data(:,1); datestr(datenum(sprintf('%d',date),'yyyymmdd'),'dd-mm-yyyy') but only the first row comes with the result. How do I modify so that it converts all the other rows?
|
Pages: 1 Prev: Use of uigetfile() together with uiwait() Next: Replacing NaN Values...? |