Turn text with date to date type - excel

I've searched on the internet and couldn't find. The only solution I found was to download kutools, and I can't do it.
I've made a macro that gets some values from an intranet, but I need the type of cell to be in date so I can work around it and filter it.
I don't know if I explained it correctly, and sorry if my english isn't the best.
I made an image to better explain it.
How it currently is / How I want it to be:

You can use the DATE and TIME functions to convert your text to date/time format.
=DATE(2018,MID(A2,4,2),LEFT(A2,2))+TIME(MID(A2,7,2),RIGHT(A2,2),0)
Using Filters:

Related

How to properly format dates in Google Sheets or Microsoft Excel

I have a spreadsheet I need to make in Google Sheets. The source of some of the data is exported to an Excel sheet. The data arrives in a dd/mm/yyyy format and I need to display it in a MON d format (Ex Sep 5).
The problem is both excel and sheets look at the date that arrives and think it is mm/dd/yyyy.
For example, 02/08/2022 is believed to be Febuary 8 even though it should be Aug 2. The problem then arises that neither of these platforms end up knowing how to convert this to Aug 2 and I end up having to do this manually.
Does anyone know how to get around this?
I have tried adjusting the format of the date, as well as using DateValue to convert (this fails since it understands the date as mm/dd/yyyy even when it is dd/mm/yyyy).
Any leads would be appreciated!
Thanks!
In Google Sheets, choose File > Settings > Locale and select a locale that uses the dd/mm/yyyy date format, before importing the data. You can then format the date column the way you prefer.
in gs:
=TEXT(REGEXREPLACE(A1&""; "(\d+)\/(\d+)\/(\d+)"; "$1/$1/$3"); "mmm d")
Try the following and format the result to your liking
=INDEX(IF(ISNUMBER(U2:U5),U2:U5,
IF(U2:U5=DATEVALUE("1899-12-30"),,
(MID(U2:U5,4,3)&LEFT(U2:U5,3)&RIGHT(U2:U5,4))*1)))
(Do adjust the formula according to your ranges and locale)
Functions used:
INDEX
IF
DATEVALUE
ISNUMBER
TRUNC
MID
LEFT
RIGHT
Well, for a formulaic solution, if the date is in A1, then the following places the correct date in B1:
=DATEVALUE(TEXT(A1,"DD/MM/YYYY"))
The TEXT function makes a string that will be the same form as your imported string out of the date produced during import. DATEVALUE then gives the proper date you desired.
The trick is in the TEXT step in which you reverse month and day in the string for DATEVALUE.
Naturally, instead of a helper column, it could just be wrapped around any reference to a date from column A, though one would have to remember to do so for all the years the spreadsheet is in use.
If you are importing, not just opening a .CSV file via File|Open and going from there, you have an opportunity to solve all your problems. You use the Ribbon menuing system's Data menu, select the very leftmost thing, Get Data and from the (no arguing THIS isn't a menu) menu that drops down, Legacy Wizards, then finally From Text (Legacy) which will open the old Excel Import Wizard. (You may notice this is very like the Data|Text to Columns Ribbon menu choice and that is because that choice is the old wizard minus the steps at the start that go looking to another file for the data because it knows, by law, that it has to already be in the spreadsheet... in other words, it looks the same because it IS the same.)
Then make selections for the first couple dialogs it presents you to get to the dialog in which you tell it to import columns as whatever: general (let Excel decide), text, date, and do not import. Choose Date and make the selection of DMY to import them properly as you desire them to be so you are never presented with the problem at all.
As you might guess, you can use the abbreviated wizard via the "Text to Columns" feature to do the same thing after import when you see they are reversed. Since it is a single column of data, the result will overwrite the original simplifying your work.
Why does this happen at all? Well, the "locale" folks have the idea. When Excel imports numbers that are in a form it recognizes could be a date, it looks to the operating system settings for the selected ways dates are understood. So if your operating system believes a date should be displayed "Month Day, Year" and Excel has a set of data it thinks fits that mold, it will convert them all using it. So you get those Feb 8's rather than Aug 2's.
Interestingly, it does two other things of note:
It looks at 8, count 'em, 8 rows of data to decide the data fits the pattern. Even with 1,000,000 rows to import, it looks at... 8.
Then it does them ALL as if God himself wrote the "8"... and dates like 25/03/2022 get imported as text not a real date, because they (oh, obviously) can't be dates... "25" can't be a month!
It IS possible to change settings (DEEP settings) to make Excel consider X number of rows in a data set before deciding such things. I found them here, on the internet, once upon a time, though I shouldn't like trying to find them again. It will consider up to a million rows in such an import, but... that'd make it pret-ty slow. And that's a million rows for EACH data column. I won't even say that "adds up" - I'll point out it "multiplies up."
Another technique is to add some number of starting rows to force the desired pattern onto the import. I've heard it works in TIME column imports so it ought to in DATE column imports but I've not verified such.
My bet is you will find the use of the "Text to Columns" feature of most use if you can use a hands-on approach - it does require literal action on your part, but is a fast operation. If you will see others using the spreadsheet though... well, you need a formulaic solution or a VBA one (macro with button for them to have some fun clicking as their reward for doing what they were trained to do instead of complaining to the boss you make bad spreadsheets). For a formulaic solution, the above formula is simple.
Last thought though: there's no error-checking and error-overcoming in it. So a date like "25/03/2022" in the data that imported as literal text is a problem. For handling the latter, an up-to-date approach could be:
=IF(TYPE(A1)=1,DATEVALUE(TEXT(A1,"dd/mm/yyyy")),DATE(INDEX(TEXTSPLIT(A1,"/"),1,3),INDEX(TEXTSPLIT(A1,"/"),1,2),INDEX(TEXTSPLIT(A1,"/"),1,1)))
in which the DATE(etc. portion handles finding text of the "25/03/2022" kind. Lots of less up-to-date ways to split the text Excel would have placed in the column, but since demonstrating what to do if it existed was the point, I took the easy way out. (Tried for a simple version but it wouldn't take INDEX(TEXTSPLIT(A1,"/"),1,{3,2,1}) from me for the input parameters to DATE.) TYPE will give a 1 if Excel imported a datum as a date (number), and a 2 if brought in as text. If empty or strange strings could exist, you'll need to deal with what those present you as well.

How to parse string timestamp into date

I have a text value that looks like this: 2019-03-25T06:05:00-07:00. The general format is yyyy-mm-ddThh:mm:ss-GMT. I don't care about the GMT part. I am trying to use this text field to make time series scatter plots in excel.
I want to convert it to a timestamp as simply as possible. I currently do this using a bunch of formulas:
Input: 2019-03-25T06:05:00-07:00
Extract parts of time individually: =value(mid(input_cell,12,2))
Use date() and time() to get timestamp types
Add them together per this answer: https://stackoverflow.com/a/41164517/11163122
Use custom formatting to get a timestamp value
Output: 3/25/2019 6:05:00 AM
In total this took me 8 cells and custom formatting. This is too complicated. What is a simpler/more elegant way to do this?
You can use:
=--REPLACE(LEFT(A1,19),11,1," ")
and format as desired
Turns out the timestamp type is ISO 8601: https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations
This led me to this answer: https://stackoverflow.com/a/26315881/11163122
Using the formula there, I found this to be a sufficient solution. If anyone out there has a better method, please speak up! :)

Select filtering and applying quantity amount to listed percentages

I tried to search but didn't find anything that was exact to what I was looking for. Let's say that I have the Investment$$ and I want to allocate that amount to only Items = to Toy Story and where Character begins with TS. The Investment $$ should only be applied to "Toy Story" and where character begins with "TS".
Apologies on not being able to embed the pictorial example to this message.
I need to write this in VBA. My questions is, is the best way to do this through a vlookup (programmed via VBA)? I want to avoid having the $1000 applied to the wrong movie title and even when it is applied to the right one (Toy Story) I want to make sure it's applied to the right ("TS") ones.
I'll also experiment on my end as well.
Pixar Movie Example
No need for VBA here. You can go with a plain vanilla Excel formula.
What you need in this situation is a key/ID item for your VLOOKUP - how you make that key is up to you, but with it you can easily utilize VLOOKUP. See my below example:

Format a date like "20110822" in Google Open Refine (or Excel)?

I have a dataset that has two different date formats in the same column. Some are formatted like:
2008-05-15T00:00:00Z
and others are formatted like:
20090804
Google Open Refine will recognize the first type as a date and will sort and allow me to perform other operations on it. I can't figure out how to format the second type into a date. A transformation of:
value.toDate()
throws an error, as does most everything else I try. This seems like a simple problem but Googling is not helping.
Hope it helps (might not!) but with 20090804 in A1:
=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))
should return a value formatted as a recognisable date.
Might be wrapped in a condition like so:
=IF(LEN(A1=8),DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2)),A1)
such that either the first format is returned or the alternative version, according to requirement.

Importing Excel with Coldfusion - Receiving strange date format mm\/dd\/yyyy

I am using ColdFusion 9 to import data from an Excel (2007, xls) spreadsheet. One of the columns being imported is a date field. In most cases, the date comes across fine, however in some instances it appears that something strange is happening with the date format. It comes across as mm\/dd\/yyyy. I don't know what is adding those additional \'s. The specific error is obvious:
"11\/15\/2012 is an invalid date or time string."
Looking directly at the spreadsheet, and within the cells themselves, the date appears formatted correctly as mm/dd/yyyy.
Does anyone know what might be causing this?
Follow-Up
Thanks for the helpful answers. In the end, the best solution was from CoderSeven. I used Replace(dateString, '\', '', 'all') to remove the offending slash and process the data through. This proved to be the best solution because I am processing spreadsheets from potentially tens of thousands of individuals, and while I control the format of the spreadsheet they use, I cannot control whether they type or cut-and-paste the data into the fields. Ultimately I would love to know where that extra slash came from, but this solution worked well.
This isn't really an answer as to why this is happening, but it is a work-around.
Just use Replace(yourdate, '\', '').
Personally, I tend to take the stance of:
If a MS product does something weird, the best solution is to just make sure you can handle that weirdness instead of trying to figure out where that weirdness is coming from.
Not that MS products are bad, it just usually saves you alot of time an effort.
"11\/15\/2012 is an invalid date or time string." One problem might be that the dates on your spreadsheet are not strings they are excel time values - which are basically integers. Perhaps converting these cells to a text format using:
=TEXT(C7,"mm/dd/yyyy")
might solve the problem. Just to be safe I would change to format to text as well. Good Luck.

Resources