Thread Subject: converting times

Subject: converting times

From: Steve

Date: 27 Jul, 2007 15:24:28

Message: 1 of 4

I have an excel file with a column of times in the format H:MM PM (i.e. 1:36 PM, 12:01 AM, etc.). I would like to be able to import this column into matlab and convert the times to a 24-hr decimal equivalent. For example,

1:36 PM = 13.6000
12:00 AM = 24.0000
12:01 AM = 00.0167

I think I can do it with a combination of 'datenum' and 'datestr', but I can't quite figure it out. Any suggestions? Thanks.

Subject: converting times

From: Andriy Nych

Date: 27 Jul, 2007 15:39:06

Message: 2 of 4

"Steve " <steveDEL.bachmeierDEL@yahoo.com> wrote in message <f8d2nc$a3a$1@fred.mathworks.com>...
> I have an excel file with a column of times in the format H:MM PM (i.e. 1:36 PM, 12:01 AM, etc.). I would like to be able to import this column into matlab and convert the times to a 24-hr decimal equivalent. For example,
>
> 1:36 PM = 13.6000
> 12:00 AM = 24.0000
> 12:01 AM = 00.0167
>
> I think I can do it with a combination of 'datenum' and 'datestr', but I can't quite figure it out. Any suggestions? Thanks.

Hope this will do the job
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> mod( datenum('1:36 PM'), 1 )*24
ans =
   13.6000
>> mod( datenum('12:00 AM'), 1 )*24
ans =
     0
>> mod( datenum('12:01 AM'), 1 )*24
ans =
    0.0167
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Subject: converting times

From: Daniel Walker

Date: 27 Jul, 2007 15:58:43

Message: 3 of 4


or... if you once end-up with a matlab datenum-format, you can also use datevec to get the hours/min/sec

>> num = datenum('19-May-2000 11:36:00');
>> vec = datevec(num);
>> dec_time = vec(:,4)+vec(:,5)/60+vec(:,6)/3600

dec_time =

   11.6000

D.

Subject: converting times

From: Steve

Date: 27 Jul, 2007 22:46:54

Message: 4 of 4

Both suggestions work very well. Thank you both.

"Daniel Walker " <dwamail.nospam@gmx.ch> wrote in message <f8d4nj$nn$1@fred.mathworks.com>...
>
> or... if you once end-up with a matlab datenum-format, you can also use datevec to get the hours/min/sec
>
> >> num = datenum('19-May-2000 11:36:00');
> >> vec = datevec(num);
> >> dec_time = vec(:,4)+vec(:,5)/60+vec(:,6)/3600
>
> dec_time =
>
> 11.6000
>
> D.

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
datestr Steve 27 Jul, 2007 11:25:23
datenum Steve 27 Jul, 2007 11:25:22
date Steve 27 Jul, 2007 11:25:22
time Steve 27 Jul, 2007 11:25:22
rssFeed for this Thread

Contact us at files@mathworks.com