From: naseeb on
Hi there,

I need to convert a date from Excel file to be used in Matlab. In Excel file it is, '14/03/2009 12:49:59 PM'

I want to convert it to '14-March-2009 12:49:59 PM' in Matlab.

I tried as,
datestr(datenum('14/03/2009 12:49:59 PM','dd/mm/yyyy HH:MM:SS PM'))
it returns, '14-Mar-2009 12:49:59' without AM/PM :((

Can anybody help me i how to do it?

Thanks
Adnan
From: Nathan on
On Jul 13, 3:59 pm, "naseeb " <adnan....(a)gmail.com> wrote:
> Hi there,
>
> I need to convert a date from Excel file to be used in Matlab. In Excel file it is, '14/03/2009 12:49:59 PM'
>
> I want to convert it to '14-March-2009 12:49:59 PM' in Matlab.
>
> I tried as,
> datestr(datenum('14/03/2009 12:49:59 PM','dd/mm/yyyy HH:MM:SS PM'))
> it returns, '14-Mar-2009 12:49:59' without AM/PM :((
>
> Can anybody help me i how to do it?
>
> Thanks
> Adnan

Why bother converting it to a datenum and back to a datestr?
Just replace the /'s with -'s

Ex:

a = '14/03/2009 12:49:59 PM';
a(a=='/') = '-'
%%%%%%%%%%%%%%%
a =
14-03-2009 12:49:59 PM


-Nathan
From: Nathan on
On Jul 13, 4:20 pm, Nathan <ngrec...(a)gmail.com> wrote:
> On Jul 13, 3:59 pm, "naseeb " <adnan....(a)gmail.com> wrote:
>
> > Hi there,
>
> > I need to convert a date from Excel file to be used in Matlab. In Excel file it is, '14/03/2009 12:49:59 PM'
>
> > I want to convert it to '14-March-2009 12:49:59 PM' in Matlab.
>
> > I tried as,
> > datestr(datenum('14/03/2009 12:49:59 PM','dd/mm/yyyy HH:MM:SS PM'))
> > it returns, '14-Mar-2009 12:49:59' without AM/PM :((
>
> > Can anybody help me i how to do it?
>
> > Thanks
> > Adnan
>
> Why bother converting it to a datenum and back to a datestr?
> Just replace the /'s with -'s
>
> Ex:
>
> a = '14/03/2009 12:49:59 PM';
> a(a=='/') = '-'
> %%%%%%%%%%%%%%%
> a =
> 14-03-2009 12:49:59 PM
>
> -Nathan

Ah, ignore that. I misread the 14-Mar-2009.

You didn't tell datestr the format you wanted:

datestr(datenum('14/03/2009 12:49:59 PM','dd/mm/yyyy HH:MM:SS PM'),'dd-
mmm-yyyy HH:MM:SS PM')
%%%%%%%%%%%%%%%%%
14-Mar-2009 12:49:59 PM


-Nathan
From: per isakson on
"naseeb " <adnan.iut(a)gmail.com> wrote in message <i1ir3o$jcm$1(a)fred.mathworks.com>...
> Hi there,
>
> I need to convert a date from Excel file to be used in Matlab. In Excel file it is, '14/03/2009 12:49:59 PM'
>
> I want to convert it to '14-March-2009 12:49:59 PM' in Matlab.
>
> I tried as,
> datestr(datenum('14/03/2009 12:49:59 PM','dd/mm/yyyy HH:MM:SS PM'))
> it returns, '14-Mar-2009 12:49:59' without AM/PM :((
>
> Can anybody help me i how to do it?
>

The default format of datestr is 'dd-mmm-yyyy HH:MM:SS' (i.e. 24h)

>> datestr(datenum('14/03/2009 12:49:59 PM','dd/mm/yyyy HH:MM:SS PM'), 'dd-mmm-yyyy HH:MM:SS AM' )
ans =
14-Mar-2009 12:49:59 PM

you have to specify the format of the output / per