I want to convert dates formatted like "March 30th 2017, 05:00:00.000" to an excel date value? What's the most elegant solution I can do this with using a cell-formula and not VBA?
This will do the standard "rd","th","st","nd"
=--(LEFT(A1,MIN(FIND({"rd","th","st","nd"},A1 & "thrdstnd"))-1)& ", " & SUBSTITUTE(MID(A1, MIN(FIND({"rd","th","st","nd"},A1 & "thrdstnd"))+2,LEN(A1)),",",""))
You can add other suffixes as you need to the formula
Then you can format it as you like.
Nested IFERROR functions can handle the variety of number ordinals.
=--SUBSTITUTE(REPLACE(A2, IFERROR(FIND("st ", A2),IFERROR(FIND("nd ", A2),IFERROR(FIND("rd ", A2), IFERROR(FIND("th ", A2), LEN(A2))))), 3, ", "), ", ", " ",2)
I used a custom number format of [Color10]mmmm dd, yyyy hh:mm:ss.000;;;[Color3]#. Beyond the fact that the text is left-aligned and the true dates are right-aligned, this will put text-that-look-like-dates in a red font and true dates in a green font.
If you want a true date and want to drop the time part then:
=DATEVALUE(SUBSTITUTE(LEFT(A1,FIND(",",A1)-1),"th",","))
You will need to nest SUBSTITUTE() functions to handle "nd" and "st" ordinals if you have them:
=DATEVALUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(LEFT(A1,FIND(",",A1)-1),"th",","),"nd",","),"st",","))
Related
Is there any way to format the following text to date and time format in Excel? Nothing I try works.
Fri, November 16 2018 8:00 PM
I have tried doing the following, with no luck.
=TEXT("Fri, November 16 2018 8:00 PM","ddd, mmm d yyyy h:mm AM/PM")
If you want to avoid VBA, then you need to use the DATEVALUE and TIMEVALUE functions. Unfortunately these functions aren't smart enough to convert the text you describe, but you can still split up the text with cell formula prior to inputting into these functions.
The following formula will convert the text Fri, November 16 2018 8:00 PM to a date/time value (assuming text is in cell A1).
=DATEVALUE(SUBSTITUTE(MID(A1, FIND(" ",A1)+1, FIND("|", SUBSTITUTE(A1," ","|",4))-FIND(" ",A1)), " ", ", ", 2)) + TIMEVALUE(RIGHT(A1, LEN(A1)-FIND("|", SUBSTITUTE(A1," ","|",4))))
You can create your own custom UDF and use it like a worksheet function:
Public Function myDateToDate(inputRng As Range) As Date
With CreateObject("VBScript.RegExp")
.Pattern = "\w{3},\s(\w+\s\d+\s\d+)\s(\d+:\d+\s\w+)"
If .test(inputRng.Value) Then
With .Execute(inputRng.Value)(0).SubMatches
myDateToDate = CDate(.Item(0)) + CDate(.Item(1))
End With
End If
End With
End Function
This will use Regular Expressions (RegEx) to grab the values in your string, and capture both the date and the time. Since within Excel all a date is is a number, you can add the first capturing group (\w+\s\d+\s\d+) (which represents the date) with the second capturing group (\d+:\d+\s\w+) (which represents the time) together. (See how the regex pattern works here).
After you have done this, you can now use your newly-created UDF by using the worksheet formula =myDateToDate(A1) - where A1 would be replaced with the cell/string that contains your date.
If you are unfamiliar with VBA, read on:
How do I access the VBE?
You can gain access to VBE by pressing Alt + F11 while you are inside your workbook.
Okay, So I have the VBE open. Now how do I apply this Sub/UDF?
In the left pane you will see your workbook object modules. This is called the Project Explorer. You will need to create a new module, which you can do by right-clicking inside the Project Explorer > Insert > Module:
Now you can paste the Sub/UDF to this new module and you are all set!
A monstrosity but should be locale independent (either US or UK):
=DATE(LEFT(RIGHT(A1,13),5),MONTH(DATEVALUE(LEFT(MID(A1,6,9),FIND(" ",MID(A1,6,10)))&"1")),MID(MID(A1,FIND(" ",A1)+1,99),FIND(" ",MID(A1,FIND(" ",A1)+1,99))+1,2))+LEFT(TRIM(RIGHT(A1,8)),7)
Nice regex solution above, you can also do it in a different way:
Function ConvertToDate(str As String) As Date
Dim arr() As String
arr = Split(str, " ")
ConvertToDate = CDate(arr(3) & "/" & Month("01/" & arr(1) & "/2018") & "/" & arr(2) & " " & arr(4))
End Function
Are there any way to multiple text wording with formula?
Also how do I change the decimal to 0.00??
Thanks in advance!
Current working code
="Should be at " &CONCATENATE(NETWORKDAYS("3/4/2018",TODAY()-1)/35*(100))
I would like to add wording after formula like this
="Should be at " &CONCATENATE(NETWORKDAYS("3/4/2018",TODAY()-1)/35*(100)) "% to Goal"
You do not need the CONCATENATE() just the & to do it:
="Should be at " & TEXT(NETWORKDAYS("3/4/2018",TODAY()-1)/35*(100),"0.00") & "% to Goal"
TEXT returns the numbers returned by the math, in the 0.00 format
The & concatenates each part into one string.
To use CONCATENATE: you would wrap the whole and replace the & with ,:
=CONCATENATE("Should be at ",TEXT(NETWORKDAYS("3/4/2018",TODAY()-1)/35*(100),"0.00"),"% to Goal")
But that is more typing than just using the &
Just for the sake of an alternative,
=TEXT(NETWORKDAYS("3/4/2018", TODAY()-1)/35, """Should be at ""0.0%"" to Goal""")
Modify 0.0% to suit your desired percentage accuracy.
To preserve your number for future calculations use,
=NETWORKDAYS("3/4/2018",TODAY()-1)/35)
Then format the cell with a custom number format of,
"Should be at "0.0%" to Goal"
'optional full format mask with +, -, zeroes as hyphens and red text (to note mistakes in input)
"Should be at "0.0%" to Goal";"Should be at "-0.0%" to Goal";_(* "-"_);[Red]_(#_)
This preserves the raw percentage for further calculations while displaying the expanded text.
I have an Excel file that must work for english & french computer.
I need to concatenate dates in the format yyyy-mm-dd, so for my english user, I need to do:
="your date = "&TEXT(A1,"yyyy-mm-dd")
That works, but not in french Excel, where I need to do
="your date = "&TEXT(A1,"aaaa-mm-jj")
How can I print the same date to both my users, independently of theirs Excel langage locale?
English TEXT function vs French TEXTE function.
And yes, the date format string are localized...
To get the date in right format use:
=YEAR(A1) & "-" & RIGHT("0" & MONTH(A1),2) & "-" & RIGHT("0" & DAY(A1),2)
I found this link which seems to treat your issue :
If you are using the TEXT worksheet function because it is part of a larger formula, then you can instruct the function itself to use a different language for its output. You do this by including a language code (formally called an LCID) within brackets, in this manner:
=TEXT(A1,"[$-409]mmmm, yyyy")
Where you could specify the text to display according to the language you want.
I used to cope with this issue as follow assuming you're on a eng MSExcel:
1. I create a named formula (returns true when it's a fr region MSExcel)
name: xlFR
refers to: = text(Today(),"d") = "d"
click OK
2. in your formula you decide on xlFR
ex: = Text(today(), if(xlFR,"jj-mm-aaaa","dd-mm-yyyy") )
That's it.
Hope this helps.
I use this vba function in my formulas:
Function DateToText(MyDate As Date)
DateToText = Format(MyDate, "DD/MM/YYYY")
End Function
I am trying to generate a customer number using the first three letters of the customers last name, the first name initial and middle initial, followed by the last four of their phone number. How would I do this? All I need is the formula.
First_Name Middle_Initial Last_Name Street_Address City State Zip Phone
Nathaniel E. Conn 6196 View Ct Lancing TN 37770 567-273-3956
Something like this (assuming a table with [structured-references], fill in the actual cell names if not):
=LEFT([LastName] & "---", 3)
& LEFT([FirstName] & "-", 1)
& LEFT([MiddleInitial] & "-", 1)
& RIGHT([PhoneNumber] & "----", 4)
I have used dashes ("-") to fill in any spaces where the field might be smaller than the number of characters you need from it. You can change them to any fill character that suits you.
Well, it depends on if each piece of data has its own column, looks like it does.
You can use the left/right functions to parse the data out of your columns.
=CONCATENATE(RIGHT(C1,3) & LEFT(A1,1) & LEFT(B3,1) & RIGHT(H1,4))
I would do:
=MID(CELL_LAST_NAME;1;3)&MID(CELL_FIRST_NAME;1;1)&MID(CELL_MIDDLE_NAME;1;1)&MID(CELL_PHONE;LEN(CELL_PHONE)-3;4)
How can I convert 20110114 (YYYYMMDD) to week, eg WK02-11, in excel ?
Thanks.
First convert the number in a date. Supposing your number is in A1 cell
=DATE(LEFT(A1;4); MID(A1;5;2); RIGHT(A1;2)
Then use WEEKNUM
=WEEKNUM(DATE(LEFT(A1;4); MID(A1;5;2); RIGHT(A1;2), 2)
(gives 3)
Then, if you want, you could embellish the result:
="WEEK-" & WEEKNUM(DATE(LEFT(A1;2); MID(A1;5;2); RIGHT(A1;2), 2) & "-" & LEFT(A1;4)