Excel 2010 Convert text string to Full date & 24 hr time - excel

Program: Excel 2010
Issue: External report gives me a text string, I want to convert it to Date & 24 hour time.
141221205535 needs to be:
14/12/21 20:55:35
I have tried text to columns making the result show: YMD
I have then tried using the format cells option: (custom) yy/mm/dd hh:mm:ss
* I receive a string of ######## in the Sample field in the formatting box.
I have tried also just using the date/time version, no seconds
1412212055 needs to be:
14/12/21 20:55
ideally, if possible:
20141421 2055 or 2014/14/21 20:55 I will accept
I can not alter the report as it comes through a 3rd party and I am pulling the date from a 'reference' field. The report, when downloaded, is in CSV and there is no existing formatting on the data.
I need to convert this as my sales report then needs to be sorted by date order.
Note: If I do use the seconds in the string, I get the weird looking scientific number. So i've had to reduce the digits, this isn't ideal, is there a way to avoid the scientific number whilst the process of changing 'text to date' is happening?
Thanks in advance.

I used this formula to convert:
=TEXT(A1,"2000-00-00 00\:00\:00")+0
format result cell in required format, e.g. yyyy/mm/dd hh:mm:ss
If you don't want the seconds in the underlying value you can use this version
=TEXT(LEFT(A1,10),"2000-00-00 00\:00")+0
These formulas work because TEXT function converts your value 141221205535 to a text value 2014-12-21 20:55:35, then, because that is a valid date/time format in Excel the +0 "co-erces" the text value to a serial number representing the correct date/time in Excel.....so you can then simply format the result to display any way you want.
Note that I'm assuming all dates will be in the current (21st) century.....

A formula like this would work -
=TEXT(DATE(LEFT(A1,2),MID(A1,3,2),MID(A1,5,2))+TIME(MID(A1,7,2),MID(A1,9,2),MID(A1,11,2)),"yy/mm/dd hh:mm:ss")
If your format always has 12 digits

You'll need to add the datevalue with the timevalue to get also the HMS
for example (suppose the text is in D5 cell):
=DATEVALUE(LEFT(D5,2)&"-"&MID(D5,3,2)&-MID(D5,5,2))+TIMEVALUE(MID(D5,7,2)&":"&MID(D5,9,2)&":"&RIGHT(D5,2))`

Related

In Excel how do I format cells correctly to work with the following date/time format?

Could someone please tell me what cell format I should use to format the following so that they are recognised in a date time format I can then use to sort from oldest date to newest date please?
02-DEC-21 21.32.01.666000000
02-DEC-21 22.16.50.588000000
03-DEC-21 00.31.06.414000000
03-DEC-21 03.50.11.644000000
03-OCT-21 18.04.41.267000000
04-DEC-21 05.39.27.832000000
I’ve tried using dd-mmm-yy hh.mm.ss.000 (can’t enter more than three 0’s in milliseconds) and also without the .000 at the end but the cells don’t get recognised as dates when I try and sort them
Thanks
You can use two formulas to retrieve the date part and the time part.
I named the range with the dates DateColumn
To retrieve the date part: =DATEVALUE(SUBSTITUTE(LEFT(DateColumn,9),".",":"))
To retrieve the time part: =TIMEVALUE(SUBSTITUTE(MID(DateColumn,11,8),".",":"))
To retrieve the whole date incl. time:
=DATEVALUE(SUBSTITUTE(LEFT(DateColumn,9),".",":")) + TIMEVALUE(SUBSTITUTE(MID(DateColumn,11,8),".",":"))
These formulas return a number, e.g. 44532 for 02-DEC-21 or 0,92835648 for 22.16.50 or 44532,92835648 for the whole date with time. You have to format them accordingly.
But be aware: this will only work on an english system.
E.g. on a German system only Dez or Okt would get recognized.

Excel custom time format with optional hours

I have a range of data which are in a time format of hh:mm.ss (my original dataset is imported through a csv this way). I need to transform it to a correct format (hh:mm:ss) to make calculations and that's easily done using the replace functionality.
The issue is that some of these data don't have the hh part, they are just mm.ss, so when I replace "." with ":" they become hh:mm instead of mm:ss, e.g. 06m.30s becomes 06h:30m.
Does anyone know how to make a custom time format that will take as default value the mm and include the hh only when necessary?
This assumes that during the import process, the time column is imported as TEXT
EDIT: Formula shortened.
Convert the values to a REAL Excel time
=TIMEVALUE(SUBSTITUTE(IF(ISERR(FIND(":",A2)),"00:"&A2,A2),".",":"))
or
=--(SUBSTITUTE(IF(ISERR(FIND(":",A2)),"00:"&A2,A2),".",":"))
Apply your desired Time format to the result
hh:mm:ss

Convert Excel date to yyyymmdd format

Note: There are questions asking the opposite, I am asking how to convert original Excel date that has underlying numerical value (for example, 27 May 1997 would correspond to 35577) into yyyymmdd format.
I have an Excel file where originally the dates were entered manually. Excel displays them as dates, but as you know they have a numeric underlying value. I.e., in the example I gave above, if you export this date into any other statistical software (i.e., Matlab or R), the value would be the underlying numeric counterpart.
What I need to do is to convert these "original" Excel dates into yyyymmdd format and then export them elsewhere.
Any suggestions are welcome.
See if this works for you -
%// For demo couple of values are assumed, but these are the values
%// that you have got from excel file
numerical_vals = [35577 ; 35579]
date_array = datevec(numerical_vals);
date_array(:,1) = date_array(:,1)+1900;
out = datestr(date_array,'yyyy/mm/dd')
Output -
out =
1997/05/27
1997/05/29
First, you should check your date setting in your computer.
Navigate to :
Control Panel -> Clock and Region -> Region-change date, time or
number formats -> Additional Settings -> Date
There change the Short date under Date formats (yyyy/MM/dd), then apply them in both windows and click ok. Restart the excel and it should work!
If it still doesn't work, you can check the format cell in excel, and convert the cells into dates.
Besides, there's a function in R called as.Date(x, format, tryFormats = c("%Y-%m-%d", "%Y/%m/%d"), which also could work.

Date format YYYY-MM-DD+11:00 convert in to YYY-MM-DD HH:MM:SS

I Received excel data with following format
Date format YYYY-MM-DD+11:00 (Ex 2014-02-15+11:00 /2014-02-18+13:00)
Now I need to convert into this format
2014-02-18 HH:MM:SI
Please help me to do this
cheers
Just did a quick test. It's a little sloppy, but this formula will work. For the sake of argument, it assumes that the data you're trying to convert is in A1 of the current sheet, that it's all the same length, and that the format is "General":
=SUM(DATEVALUE(LEFT(A1,10)),TIMEVALUE(RIGHT(A1,5)))
Wherever you use the above formula, change the format to the Custom Format YYYY-MM-DD HH:MM:SI. I'm not sure what you're looking for with SI. I'm taking that literally. That custom format will display the seconds value and then the letter I. If you're looking for a different value, like milliseconds, then you can look that up. But if the data you're converting is in a "General" format, when you convert it, it won't have seconds or milliseconds, anyway. Those will all get converted to 00s.

Figuring Excel date format programmatically

I have a program that gets input in the form of an excel which it reads by querying (select * into a dataset).
The excel is created by the customer.
The excel contains a date column.
The problem is, that when looking into the dataset, the date column format is sometimes like mm/dd/yyyy and sometimes dd/mm/yyyy. (1/25/1970) (25/1/1970)
I guess it depends on the locale on the machine which the excel was made.
How can my program know what is the date format in the excel?
Not sure whether your question is about output or input...
For output:
You did not mention the database type. But the rule is: make your dates the american way: mm/dd/yyyy. For Jet, I generally use Format(MyDate, ""\#dd\/mm\/yyyy\#"")
("\" is the escape character, it makes sure the next character is output "as is")
For input:
Try reading the cell format ? range("a1").NumberFormat
However on my PC, with French setup a date displayed as 15/2/2011 has a returned format = m/d/yyyy so little use here !

Resources