I have a text column containing dates in the following fashion:
01:00 Friday 18/11/16
...however, when I format the column as date, time or custom, the existing cells do not format.
I've also tried =DATEVALUE(A2) but it returns a #VALUE! error.
To get the time from this cell:
=LEFT(A2,5)
To get the date from this cell:
=RIGHT(A2,8)
To get the weekday text from this cell:
=RIGHT(LEFT(A2;LEN(A2)-9);LEN(LEFT(A2;LEN(A2)-9))-6)
Alternatively, you can use the date portion to find the weekday directly:
=TEXT(RIGHT(A2,8), "ddd")
OR
=TEXT(RIGHT(A2,8), "dddd")
And to get the weekday in numbers:
=WEEKDAY(RIGHT(A2,8))
You can't use ask excel to parse a no-standard format date. Furthermore, DATEVALUE will drop the time from the value.
What you can do is separate the date and time, parse them separately and add them up:
=DATEVALUE(RIGHT(A1, LEN(A1)-FIND(" ", A1, FIND(" ", A1)+1))) +
TIMEVALUE(MID(A1, 1, FIND(" ", A1)-1))
If the date and time have fixed length, you can replace the FIND with their respective length of 8 and 5.
Related
Is there a way for me to format a column where the values I enter in the format HH:MM (elapsed time, not datetime) are converted to hours in decimal, preferably in the same column via some custom formula?
For example,
HH:MM
H (Decimal)
07:39
7.65
02:15
2.25
06:00
6
At the moment, I manually calculate the equivalent and enter them into the column but it would be nice to directly copy a timestamp and have the column automatically format it but I couldn't see an option for this in Date/Time formatting settings.
Simply multiply your hh:mm durations by 24, ensuring that the cells where you want the decimal hours returned are formatted as 'Number'. Or to force formatting as a number using a formula: =text(duration_cell*24,"#.##") where duration_cell is a cell with the duration in hh:mm format.
There is no way to do that I know of because Excel stores times/dates as floats. Each 24 hour period equals 1, therefore 7:33 equals .31458 Therefore, you won't be able to do this without a helper column.
You can do this with either #The God of Biscuits answer, or alternatively your helper column can have the formula:
=(A1*24)
and you set that column's cell format to Number.
All date and time is a format of a double value.
Time is the amount after the comma.
And all in front of comma is days since 00.01.1900.
Meaning 07:37:00 = 0,32 days.
Excel have a ways to pull the amount of hours with =HOUR('Your referance date time cell value')
You can aply this formula: =HORA(A2)+(MINUTO(A2)/60)
Is there a method to convert these column in data format? (gg/mm/aaaa hh:mm:ss)
DATE : 20220601 >>>> 2022/06/01
HOUR : 3047 >>>>> 00:30:47 (hh:mm:ss)
I have serious problem with column B, i need to convert it in (hh:mm:ss). Someone can help me?
The final result should be "01/06/2022 00:30:47"
If you have Excel 365 you can use this formula:
=LET(HourText,TEXT(B2,"000000"),
DateText, A2,
HourFinal,TIME(LEFT(HourText,2),MID(HourText,3,2),RIGHT(HourText,2)),
DateFinal, DATE(LEFT(DateText,4),MID(DateText,5,2),RIGHT(DateText,2)),
DateFinal + HourFinal)
It first takes the text-hour and the text date.
Text hour is formatted as hhmmss - to have the zeros for hour if missing. Then it is easier to return the true hour.
Adding both values (date + hour (yes this is mathematical addition) returns the date.
You can then format the date as you like, e.g. as dd/mm/yyyy hh:mm.ss
Try-
=TEXTJOIN("/",TRUE,MID(A1,{1,5,7},{4,2,2})) & " " & TEXTJOIN(":",TRUE,MID(RIGHT("00"&B1,6),{1,3,5},{2,2,2}))
For pure date value use below function then use cell format to show your desired date/time format.
=DATEVALUE(TEXTJOIN("/",TRUE,MID(A1,{1,5,7},{4,2,2})))+TIMEVALUE(TEXTJOIN(":",TRUE,MID(RIGHT("00"&B1,6),{1,3,5},{2,2,2})))
Here is an easy alternative solution, using the TEXT() Function with a Custom Formatting for Dates 0000\/00\/00 while for Times 00\:00\:00
• Formula used in cell C2
=TEXT(A2,"0000\/00\/00")+TEXT(B2,"00\:00\:00")
So, the first part of the TEXT() function returns & converts the Numbers into Dates, while the second part returns & converts the Numbers into Times, and as we know that Dates & Times are stored as Numbers in Excel, so the Integer part which represents the Dates and the Decimal which represents Times, when added to together returns a Number with Decimals using the TEXT() Function.
Hence if the cells are not formatted before then please select the cell or range and press CTRL+1 --> Format cells Dialogue Opens --> Number Tab --> Category --> Custom --> and type by removing General as dd/mm/yyyy hh:mm:ss or as per your region it will be gg/mm/aaaa hh:mm:ss
Note: For more inspiration on converting Dates when shown like those numbers, you can refer this link, I have shared a whole lot of alternatives.
CHANGE THE DATE FORMAT
I'm trying to extract dates from the substring in column D2/D3 in column L2/L3. However, the date format within a substring differs. Sometimes the dates are entered in MM/YY format, or MM/YYYY format. Right now I'm using the formula below, but I have to change the 5 to 7, when the date in the substring is entered in MM/YYYY format.
=SUBSTITUTE(SUBSTITUTE(MID(D2,FIND("/",D2)-2,5),"-",""),"/","/01/")*1
example of substring in column D
If there will always be exactly 1 slash, then you can use a two step formula. Assume it is MM/YYYY. Try to extract that first as a date. If that fails, then it's the MM/YY format.
=IFERROR(
DATE(MID(D2,FIND("/",D2,1)+1,4),SUBSTITUTE(MID(D2,FIND("/",D2,1)-2,2), "-", ""),1),
DATE(MID(D2,FIND("/",D2,1)+1,2)+2000,SUBSTITUTE(MID(D2,FIND("/",D2,1)-2,2), "-", ""),1)
) \-----------------------------/ \---------------------------------------------/ ^
| | |
year month day
I had to use a function DATE() to build a real date value, so that if it fails it will return an error, so that it will use the second part to use a two digit year. (Don't include the year/month/day note in the actual formula...)
Or even better, since your formula already works for MM/YY, then if the first DATE() conversion fails, it will use your formula. That way you don't have to assume a YY value is the year 2000 or later...
=IFERROR(
DATE(MID(D2,FIND("/",D2,1)+1,4),SUBSTITUTE(MID(D2,FIND("/",D2,1)-2,2), "-", ""),1),
SUBSTITUTE(SUBSTITUTE(MID(D2,FIND("/",D2)-2,5),"-",""),"/","/01/")*1
)
Is there any option to compare dates with Date format yyyymmddhhmmss with the current date?
Basically one of my external source have this type of date and I have to compare this date with the current date and check difference in between. I have tried to split those date with LEFT,MID,RIGHT functions, so basically, I have two columns - first with date, second with time, but I cannot find any option to subtract current date with date in column, because results are not coming correct.
Sample of date: 20161112203545
after splitting: 2016-11-12 20:05:45.
Any ideas?
Image produced below with formulas is self explanatory.
Your date :20161112203545 in D4
Formula to convert date in E4 :
=DATE(LEFT(D4,4),MID(D4,5,2),MID(D4,7,2))+TIME(MID(D4,9,2),MID(D4,11,2),RIGHT(D4,2))
Today's Date in F4 : =TODAY()
Formula to get date difference in days in G4 : =DATEDIF(F4,E4,"d")
EDIT
The alternative to Excel DATEDIF would be a User defined function (UDF) that internally uses the VBA DATEDIFF function:
This UDF accepts three parameters:
Start_Date: The days from which the period begins.
End_Date: It is the last date of the period that you wish to calculate.
Unit: It specifies the interval by which you want the difference. Here the unit accepts following values.
Value Description
YYYY Year
Q Quarter
M Month
Y Day of year
D Day
Public Function xlDATEDIF(Start_Date As Date, End_Date As Date, Unit As String) As String
xlDATEDIF = DateDiff(Unit, Start_Date, End_Date)
End Function
In this case usage will be, put formula in H4 =xlDATEDIF(F4,E4,"D")
HTH
Taking the date as
20161112203545 after splitting: 2016-11-12 20:05:45
Is going to cause you some issues as Excel assigns date values with a serial number, and it's going to throw that number off. You could use the =today() function and set it up where you have the date entered, say it is in cell A1, then =A1-today() (formatted as a number) should give you the difference in the amount of days.
Microsoft explanation of using Dates in Excel
The scenario I have is as follows:
Cell A1 - contains the name of the current month, e.g. "October"
Cell A2 - contains the value of the current year, e.g. "2014"
Cell A3 - contains the value of a given day, e.g "22"
I'd like to populate A3 with a formula that will give it the value 22 October 2014 and have this formatted as a date so I can perform comparisons and calculations in other cells - so along the lines of 22 + A1 + A2. I've tried using the CONCATENATE function but this doesn't let me format the cell as a date.
Is something like this even possible using the standard Excel functions?
You're looking for the DATEVALUE function. It can convert month names into a numerical date expression, which you can then format as a date (dd/mm/yyyy in the example below).
=DATEVALUE(A3 & " " & A1 & " " & A2)
As a bonus, this will also work if A1 contains short-form month names i.e. Jan, Feb, Mar, etc.
I just did a bit of testing, which showed that you can also drop the " " space delimiters entirely:
=DATEVALUE(A3&A1&A2)
In fact, just using -- to force Excel to treat the concatenated string as a numerical value works as well!
=--(A3&A1&A2)
So far, my testing has not found any instance where -- doesn't work as well as DATEVALUE. Leaves me wondering what the point of DATEVALUE is.
Try this:
=DATE(A2,MATCH(A1,{"January","February","March","April","May","June",
"July","August","September","October","November","December"},0),A3)
You can also use this formula
=(A1&A2)+A3-1
format result cell in required date format