Parse non-standard Date/Time format to Date in VBA - excel

I have many strings of text preceded by a timestamp with the form
Oct 19, 2011, 5:00:40 AM GMT
I tried using isDate to check if some subset of the string is a Date, but the only section that seems usable is
Oct 19, 2011
and I would like to have the time data as well.
Thanks in advance!

I'm sure there are cleaner ways to do it but this might help you get by:
For Date value enter (shown in cell B2): =DATEVALUE(MID(A2,1,FIND(",",A2,FIND(",",A2)+1)-1))
For Time value enter (shown in cell C2): =TIMEVALUE(MID(A2,FIND(",",A2,FIND(",",A2)+1)+1,12))
Results:

Related

How can I split" Feb 9 2022, 9:55 PM" in excel by a formula?

The Format is Date
=INT() didn't work
Just because you format it as a date does not make it so. This is probably a date stored as text not a true date which if you changed to general format would change to a number. You will need to parse the string and put the "date" in a format that excel can understand then take the INT to get just the date:
=INT(--REPLACE(SUBSTITUTE(A1,",",""),FIND("{{{",SUBSTITUTE(A1," ","{{{",2)),0,","))
One note, this method only works if the month value like Feb is in the local language. If one has a local language of Portuguese Feb is not the correct abbreviation, and as such will fail.
Use the builtin date functions Day() Month() Year() Hour() Minute().

Convert date Excel

Trying to convert Italian date. I got dates from pdf like 21 Giu 2020 which I paste into Excel and then try to format cells and choose option "Date" and 14-mar-12 there but it does not respond. It does only when I change 21 Giu 2020 to 21.12.2020 then it is 21-giu-2020.
Is there any way to automate it, else I need to search upon Italian months and conver Ago to 08, Giu to 12 etc etc?
If your locale isn't Italian, I doubt that Excel would ever recognize a string like that as a date. Here is a formula that would create the date for you:
=DATE(RIGHT(A1,4),MATCH(MID(A1,4,3),TEXT(DATE(2020,SEQUENCE(12),1),"[$-410]mmm"),0),LEFT(A1,2))
The avobe usage of SEQUENCE requires ExcelO365. I also made the assumption your text is always in the pattern "dd mmm yyyy".
You'll end up with a date which you can then use number formatting of your liking.

Extracting date from from text, not in correct format

I'm trying to extract dates using excel from multiple documents, but the dates are only ever listed in the following format in a single cell
Please Pay By: Apr 10, 2019 Terms of payment: 30 Days
I have found the following resource, which is able to extract dates from text
https://www.extendoffice.com/documents/excel/4776-excel-extract-date-from-text.html
and I know i can use a vlookup formula and table
=DATE(RIGHT(A2,4),VLOOKUP(LEFT(A2,3),D2:E13,2,0),MID(A2,5,2))
But im having trouble combining these two methods to be able to extract the date from the following format:
Please Pay By: Apr 10, 2019 Terms of payment: 30 Days
(Didn't know how to get stack overflow to also show the gaps so have marked the format as code)
Any help would be greatly appreciated
I think you could try, if one has O365:
In formula B1:
=DATE(--MID(A1,FIND(", ",A1)+2,4),MATCH(MID(TRIM(A1),16,3),TEXT(DATEVALUE("1/"&SEQUENCE(12)&"/2020"),"mmm"),0),MID(A1,FIND(", ",A1)-2,2))
If you don't have access to SEQUENCE use:
=DATE(--MID(A1,FIND(", ",A1)+2,4),MATCH(MID(TRIM(A1),16,3),TEXT(DATEVALUE("1/"&{1,2,3,4,5,6,7,8,9,10,11,12}&"/2020"),"mmm"),0),MID(A1,FIND(", ",A1)-2,2))
Note, if you don't have O365, you need to accept through CtrlShiftEnter

Another string to datevalue conversion for Excel

This is another question on date string to datevalue conversion.
Input format is "March 17, 2013 7:04:28 PM GMT-07:00".
(Output of SAP tool)
=DATEVALUE(B26) fails.
Any chances?
Thanks,
Gert
This should work:
=DATEVALUE(LEFT(B26,FIND(",",B26)+5))+TIMEVALUE(MID(B26,FIND(",",B26)+7,FIND("GMT",B26)-FIND(",",B26)-8))
Your looking at two different things. Datevalue is seperate from time. For example, March 17, 2013 in Datevalue is equal to 41350.
=DATEVALUE(March 17, 2013)
Timevalue of 7:04:28 PM is equal to 0.794769
=TIMEVALUE(7:04:28 pm)
Both of these require the input to be in text format, not date or time.
You'll have to parse out the string and strip off the GMT at the end. I don't think excel can evaluate time zones.
If you are using US regional settings then your text is a valid date/time format once you remove "GMT" and everything after so you can use a formula that will simply remove that part and "co-erce" to a date/time value, i.e.
=LEFT(B26,FIND("GMT",B26)-1)+0
format result cell in the required date/time format, e.g. m/d/yy hh:mm

How to convert a date entered as a string to a Date type in Excel?

I have a large spreadsheet that contains, among other things, date entries in the form of:
Fri, 03 May 2013 07:04:46 GMT
I haven't been able to find a way, within Excel proper, to manipulate this down to a date object it recognizes. The problem is, I don't extract the spreadsheet or have any control over how this data is provided, and there are a LOT of entries -- to many to manually change them. Further, while my first thought is to simply crank out a Perl script to roll through and do it for me, this won't do because I'm just prototyping a process that will be handed off to someone that wouldn't know Perl from Pearl. It needs to be something doable only in Excel, and other than sorting and basic equations and such, I'm pretty much an excel noob.
My require is simply that I need to be able to sort the column contain these values as a date.
Thanks!
If there are specifically three characters for the month, then you could use:
=DATEVALUE(MID(A1,6,11))+TIMEVALUE(MID(A1,18,8))
Format the Cell to a Date, using something like dd/mm/yyyy hh:mm:ss if you want to confirm that the time is correctly interpreted.
If you don't need the time then just omit the +TIMEVALUE().
You can use =LEFT, =MID and =RIGHT to extract the different parts of the string, and manipulate them further. The string format isn't unambiguous from your example, but I'm assuming that it's 3-char weekday, dd mmm yyyy date, and hh:mm:ss time.
If your data is in column A:
=LEFT(A1, 3)
returns Fri
=MID(A1, 6, 11)
returns 03 May 2013, and =VALUE() on that returns the date serial number for 3 May 2013.

Resources