how to work with uneven dates in Excel? - excel

I needed help as I am trouble with this recurring problem.
I have following date formats. American date format:
8/30/2013
11/1/2014
1/12/2014
For 8/30/2013 , I write =DATE(RIGHT(B2;4);LEFT(B2;1);MID(B2;3;2)), and I get it as "2013-08-30". For the other dates, I have to manually rewrite them again and again.
How can I write in one line to get 8/30/2013 or 10/12/2014 in a final date result like "2013-xx-xx?

if all entries are dates, you can use Text function:
=TEXT(B2, "yyy-mm-dd")
hope this helps.

Since you used string manipulation formulas and it worked for your first date, I believe that the date is actually text format.
As such, I would suggest using FIND to get the positions of / like this:
=DATE(RIGHT(B2;4);LEFT(B2;FIND("/";B2)-1);MID(B2;FIND("/";B2)+1;FIND("/";B2;FIND("/";B2)+1)-FIND("/";B2)-1))
It's quite long, I admit, but it's quite difficult to get substrings between two specific characters. If the year is always in that format, then you can use a slightly shorter formula:
=DATE(RIGHT(B2;4);LEFT(B2;FIND("/";B2)-1);MID(B2;FIND("/";B2)+1;LEN(B2)-5-FIND("/";B2)))

Related

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! :)

How can I get the members of a PivotTable column field to display in natural order, rather than alphabetically?

I was taught how to convert a date-as-string value that was being converted from what I wanted ("Sep 2015", "Oct 2015" etc.) to what Excel thought it should be ("15-Sep", "15-Oct" etc.) here.
When it was displaying "badly," the columns at least displayed in the right order ("2015-Sep" followed by "2015-Oct"). Now that they are "Sep 15" and "Oct 15", though, they are displaying out of "natural" order and in alphabetical order ("Oct 15" followed by "Sep 15").
This is the too-typical scenario (especially egregiously evident in software development) of the solving of one problem causing another one to rear its ugly rear.
This is how I create the "month" part of the PivotTable:
var monthField = pvt.PivotFields("MonthYr");
monthField.Orientation = XlPivotFieldOrientation.xlColumnField;
Before fixing the display format problem:
After fixing the display format problem ("15-Sep" is now "Sep 15", etc., but the months are now out of order):
Can I "have my cake and eat it, too" so to speak? If so, how?
From reading the comments, it sounds like you need to convert your C# date to an excel date. In the second comment you mention that you were able to get values "201509" and "201510" onto an excel sheet.
I suggest you separate the year and month using the LEFT() and RIGHT() functions, then use the DATE() function to get the Excel serial number for 9/1/15 and 10/1/15.
Here's a screenshot of the steps I'm think of (Happy Halloween!):
Finally, you can now format the Serial number using your formula monthField.NumberFormat = "MMM yy". Excel will realize this is a date and sort it chronologically.

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.

Problems changing date format of date as string

I am currently trying to convert yyyymmdd type of date to a ddmmyyy format.
I've tried using DATE function and something like this:
=DATE(LEFT(A3;4);MID(A3;5;3);RIGHT(A3;7))
Original date for this function is 20120401 but the formula returns: 16.12.2104.
I've tried using functions YEAR, MONTH and DAY instead of LEFT, MID and RIGHT but that's not the right way.
I also tried using DATEVALUE but since Excel probably doesn't recognize yyyymmdd as a date, it gives me a #VALUE! error.
I've found a couple of solutions for SQL but it isn't my strong side yet - and this should be achievable easily in Excel.
Is there a way to do this in Excel?
Applying =DATE(LEFT(A3;4);MID(A3;5;3);RIGHT(A3;7)) to 20120401 in A3 is effectively to reassemble the component characters as below on the left:
These effectively become converted as on the right.
The solution was simply to exclude the digits highlighted red with:
=DATE(LEFT(A3;4);MID(A3;5;2);RIGHT(A3;2))
but the locale might have been a factor and when dealing with date serial numbers and/or what appears to be a date but is a string various other issues might have been involved.
Consider:
=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))

FIxing MS Excel date time format

A reporting service generates a csv file and certain columns (oddly enough) have mixed date/time format , some rows contain datetime expressed as m/d/y, others as d.m.y
When applying =TYPE() it will either return 1 or 2 (Excel will recognize either a text or a number (the Excel timestamp))
How can I convert any kind of wrong date-time format into a "normal" format that can be used and ensure some consistency of data?
I am thinking of 2 solutions at this moment :
i should somehow process the odd data with existing excel functions
i should ask the report to be generated correctly from the very beginning and avoid this hassle in the first place
Thanks
Certainly your second option is the way to go in the medium-to-long term. But if you need a solution now, and if you have access to a text editor that supports Perl-compatible regular expressions (like Notepad++, UltraEdit, EditPad Pro etc.), you can use the following regex:
(^|,)([0-9]+)/([0-9]+)/([0-9]+)(?=,|$)
to search for all dates in the format m/d/y, surrounded by commas (or at the start/end of the line).
Replace that with
\1\3.\2.\4
and you'll get the dates in the format d.m.y.
If you can't get the data changed then you may have to resort to another column that translates the dates: (assumes date you want to change is in A1)
=IF(ISERR(DATEVALUE(A1)),DATE(VALUE(RIGHT(A1,LEN(A1)-FIND(".",A1,4))),VALUE(MID(A1,FIND(".",A1)+1,2)),VALUE(LEFT(A1,FIND(".",A1)-1))),DATEVALUE(A1))
it tests to see if it can read the text as a date, if it fails, then it will chop up the string, and convert it to a date, else it will attempt to read the date directly. Either way, it should convert it to a date you can use

Resources