Operations time durations in Excel - 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))

Related

Conver scientific format timestamp to date excel

I have difficulty in converting the timestamp recorded in excel. The format is in scientific, I would like to convert to date format in excel.
Scientific = 2.02207E+13 (in number format 20220715030838)
I expect the result will be 15-Jul-2022 03:08
Thanks
Use below formula to convert date/time value.
=--TEXTJOIN("/",TRUE,MID(A1&"",{1,5,7},{4,2,2}))+(--TEXTJOIN(":",TRUE,MID(A1&"",{9,11,13},{2,2,2})))
Then use cell format to display results as desired format. Or can use TEXT() function like-
=TEXT(--TEXTJOIN("/",TRUE,MID(A1&"",{1,5,7},{4,2,2}))+(--TEXTJOIN(":",TRUE,MID(A1&"",{9,11,13},{2,2,2}))),"dd-mmm-yyyy hh:mm")
My answer is here, make sure that singe digit date should come with 0 as highlighted in the pic. Either you can customise the format or use Text function.
If you want seconds as well then use Right(A2,2) function in Second argument in the Time function. Hope it clears.
=TEXT(INT(DATE(LEFT(A2,4),MID(A2,5,2),MID(A2,7,2)))+TIME(MID(A2,9,2),MID(A2,11,2),),"dd-mmm-yyy hh:mm")
=INT(DATE(LEFT(A2,4),MID(A2,5,2),MID(A2,7,2)))+TIME(MID(A2,9,2),MID(A2,11,2),) #customise the format.

Getting uniform date format from xlsx file in nodejs

I am reading data from an excel sheet and the 5th column is a date field. I have the following logic to ensure that the input date is converted to YYYY-MM-DD format -
var valid_from = new Date(data[counter][5]);
valid_from_new = var formatedDate = moment(valid_from).format("YYYY-MM-DD");
reqBody.valid_from = valid_from_new.toString();
I have the date 2017-10-10 to begin with and I am able to read it fine via my node app. It works for me as long as I do not edit this field in my Microsoft Excel 2010. If I edit it or simply find/replace the values, I get unix default date (1970-01-01) in reqBody.valid_from.
To find out what happens after the replacement, I checked that if I replace 2017-10-10 with 2017-10-20 and then "clear formats" (excel utility), I get 43028 displaying in the sheet, whereas for the date 2017-10-10 it remains the same, i.e. 2017-10-10. I don't understand why excel behaves like this.
Can this be handled uniformly by my application? I just want to make the "YYYY-MM-DD" format work across any excel versions. It would be fine if I could do one format change or clear format once before feeding the file and it would work.
I don't understand why excel behaves like this.
Excel behaves like that as it stores 2017-10-10 as a serial date. Meaning it is an integer representing the number of days that have past since January 1st 1900 for the Windows system. (potentially 1905 or something similar for mac). In your specific case its apparently 43028. It displays a converted date in a format people read as 2017-10-10 in your case. You will note this as your formatting for the cell is either a date of some sort or a custom user format. If you entered the date as text by leading it with a ' you would note the format does not change when you change the cell formatting. The date is actually just text and not a formatted date. Numbers that are enter in a format that looks like a date to excel, excel will usually attempt to automatically convert them to a serial date value for you. It has a built in list of formats it looks for and I believe also looks at your system settings format too.
As a side note, the decimal portion of the number represents time. Fraction of a day. 0 is 00:00:00 and .5 is 12:00:00.
Can this be handled uniformly by my application?
I am sure the answer to this is "yes" but is beyond my expertise. I highly suspect it is because your code is handling it as text initially. Things go wrong when it receives the integer from excel that represents the date in excel.

Excel dates - converting different date formats into a single format

Have a large raw data dump and I am trying to format the dates into a consistent format.
As you can see from the screenshot, there are two main formats, one custom mm-dd-yyyy hh:mm AM/PM and mm/dd/yyyy hh:mm:ss. One is stored as general, while the other as a custom value.
I've tried to =left(A2,8), converting via text() and using text to columns, but can't bring the values to a consistent value.
It appears that your Windows regional settings for Short Date are DMY or similar. It is likely your data dump is in MDY format. That is why A2 and A4 are being converted to "real dates" (although incorrectly), and A3 is not since Excel does not know what do with month = 13. You will note that A2 is 1-Dec-2015 and I suspect that in the original data it is 12-Jan-2015.
EDIT: To expand a bit on the explanation. When something that looks like a date or time is entered into an Excel cell, Excel tries to change the result to a date, parsing the input according to the Windows Regional Short Date format. This sometimes has an undesireable outcome. For example, if your Windows Format is MDY but the date is input as DMY, input with days <=12 will be converted incorrectly, and input with days > 12 will be retained as text. This behavior cannot be "turned off" and causes many complaints from those who want to enter data that looks like a date, but is not. (For example, entering an odds ratio as 1-10 or 12:3 will get converted to a date or a time)
Several options
Change the output of the data so as to have the dates in DMY format.
Instead of OPENing the data file, do a Text Import. In later versions of Excel, you will find this on the Data Ribbon ► Get External Data ► From Text. This will open the Text import wizard and allow you to specify the MDY format of the incoming data before Excel transforms it.
After you have done one of the above, the result will be a "real" Excel date or date/time and you can format it how you like.
Write a IF() where if column B specifies "Custom" change format to standard.
For AM, just remove it(replace AM with nothing). For PM add 12 to the hours and replace PM with nothing.
For custom Replace - with / and append :00 to add the seconds to the custom ones too.

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"))

converting time from excel to matlab

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.

Resources