converting time from excel to matlab - excel

I'm trying to import data from excel into matlab where the data contains a column of time where time is in the format of 00:05, 22:00 etc...
Is there a way of importing this into matlab without changing the format?
Currently, when importing the vector into matlab, it changes the values to decimals which is not what I need.

Have you tried to convert the numbers you've got from Excel file with DATESTR function?
xtimestr = datestr(xtime,'HH:MM');
This should have no problems with time. But you have to take care if you are getting dates as well, because of different date systems used by MATLAB and Excel. See When to Convert Dates from Excel Files for more details.

Related

How does Excel convert Date to Text?

I have a date 2020-01-30 (yyyy-MM-dd).
When I change the column format to Text it is getting converted to 43860.
I want to know how it is making it to 43860?
I came to know from Microsoft community that its a difference between 01-01-1900 to the written date. Then is should be 43858 . Why its 43860 ?
In Excel Date/Times are Doubles. It is the number of days since 1899-12-31. If you want to have text instead of a true date you will need to convert it by using the TEXT() Function on the worksheet or Format() in VBA.
There is an included error so that Excel could be compatible with Lotus 1-2-3. It assumes that 1900 was a leap year, which it was not. See: https://www.myonlinetraininghub.com/excel-date-and-time
=TEXT(A1,"yyyy-MM-dd")
Cited many times on SO. It's the number of days between Jan-1-1900 (or 1904) and the given date. This is what allows you to do math on dates.
https://support.microsoft.com/en-us/office/date-systems-in-excel-e7fe7167-48a9-4b96-bb53-5612a800b487

Operations time durations in Excel

I am working on a datasets in Excel in which I have a column named Duration containing values such as 11:01, 01:39:13 etc. The format here is either hh:mm:ss or mm:ss. How can I do operations such as addition & subtraction on such values?
The file is of XLSX format & I am working on the latest version of Office.
Most likely your "times" are actually text that look like times. They will need to be converted to actual times to be summed.
The issue is that if one does a straight conversion on 11:01 Excel will assume hh:mm not mm:ss
So we need to add some parsing to get the correct time format then sum the results:
=SUMPRODUCT(--RIGHT("00:"&B2:B4,8))

Excel saved decimal datas as date time

After I export my data to Excel my some of my decimal values converted to date format by Excel. For example, my decimal data was 1.25 but it seems Jan.25 in Excel. How can I re-convert to correct decimal format ?
When you import the data set the column data type specifically to number.
Without sample data (both input and resulting Excel values) it is hard to diagnose the problem.

how to prevent excel 2010 from converting times to decimals automatically when cell is pasted

As you might have come accross, MS Excel tends to convert times to decimal values. I do want it to convert the values automatically because I need the time value. Suppose I have following data:
Departure | Time
Istanbul 06:45
Ankara 01:30
I am using Concatenate function to create a desired string as Istanbul: 08:00 and Ankara: 18:30. However, when I use the formula, Excel converts hours to decimals and I get Istanbul: 0.28125 and Ankara: 0.0625. I do not want it to convert. How can I do this?
ps: This also happens when I copy time values from Excel to Notepad++. Moreover, when I import time values into PostgreSQL through add-in, I still get decimal values in the columns
You want to use the TEXT function to convert the time into the text format that you require. Something like this:
=CONCATENATE("Istanbul: ", TEXT(A1,"hh:mm"), " and Ankara: "18:30, TEXT(A2,"hh:mm"))

Excel parsing (xls) date error

I'm working on a project where I have to parse excel files for a client to extract data. An odd thing is popping up here: when I parse a date in the format of 5/9 (may 9th) in the excel sheet, I get 39577 in my program. I'm not sure if the year is encoded here (it is 2008 for these sheets).
Are these dates the number of days since some sort of epoch?
Does anyone know how to convert these numbers to something meaningful? I'm not looking for a solution that would convert these properly at time of parsing from the excel file (we already have thousands of extracted files that required a human to select relevant information - re-doing the extraction is not an option).
Excel stores dates as the number of days since 0-JAN-1900 (so 1-JAN-1900 would have a value of "1"). You can find a really good breakdown of how Excel handles dates and times here:
Dates And Times In Excel
When dates appear on screen in Excel as "5/9", "May 9th", or some such, it is a trick of the formatting and is not representative of the underlying data value. It sounds like your parsing program is pulling the underlying value, not the formatted date. In order to suggest a fix, though, I need to know what your parsing program is (Excel macro, formula, outside code, etc.).
DateTime.FromOADate (if you're using .NET) is the method you want. Excel dates are stored as doubles. If you have dates in the first two months of 1900 you might get bit by the Excel 1900 leap year bug.
From http://msdn.microsoft.com/en-us/library/system.datetime.fromoadate.aspx:
Double-precision floating-point number
that represents a date as the number
of days before or after the base date,
midnight, 30 December 1899. The sign
and integral part of d encode the date
as a positive or negative day
displacement from 30 December 1899,
and the absolute value of the
fractional part of d encodes the time
of day as a fraction of a day
displacement from midnight. d must be
a value between negative 657435.0
through positive 2958466.0.
All you need to do is format the cells correctly. Or am I misunderstanding your question -- are you saying you want to do it OUTSIDE of Excel? I wasn't sure. I'll delete this answer if it turns out to be stupid.

Resources