I have 5 columns with values (and many rows). First column is timestamp in the format dd.mm.yyyy hh:mm:ss.000
The last three zeros indicate miliseconds, e.g. 09.12.2021 22:00:34.343
We use this kind of date format (day first before month).
If I try to sort them in Excel , they get sorted alfabetically and not chronologically.
For the values below
23.10.2021 20:59:47.066
23.10.2021 21:07:17.061
23.10.2021 21:17:17.082
23.10.2021 23:42:18.008
23.11.2021 11:11:00.005
23.11.2021 11:21:00.096
24.10.2021 00:32:18.052
24.11.2021 16:42:14.046
I need to get
23.10.2021 20:59:47.066
23.10.2021 21:07:17.061
23.10.2021 21:17:17.082
23.10.2021 23:42:18.008
**24.10.2021 00:32:18.052**
23.11.2021 11:11:00.005
23.11.2021 11:21:00.096
24.11.2021 16:42:14.046
What workaround is for this?
One solution (if the Timestamps must remain as string values):
Add a helper column that converts the string values to sort-able date/time values. The formula for that would be:
=DATEVALUE(SUBSTITUTE(LEFT(A1,10),".","/"))+TIMEVALUE(RIGHT(A1,12))
Note:
a) The above is of course converts the value at cell A1
b) It assume the format is always dd.mm.yyyy hh:mm:ss.nnn
Sample Result (sorted on column B)
In case you’re wondering, the Number Format for Column B is dd.mm.yyyy hh:mm:ss.000
To convert the strings to "real dates" which can be sorted in date/time order, you can use this formula to create a Helper column
=DATE(MID(A1,7,4),MID(A1,4,2), LEFT(A1,2)) + TIMEVALUE(RIGHT(A1,12))
This formula will work independently of the Windows Regional Settings on the computer. It obviously assumes the source data is DMY, but will convert the string to a real date even if the WRS on the target compute is something else.
Original Data
Sorted
The helper column can be hidden, or deleted after the sorting is done
Related
i have a column in excel where data is in mix format as some date are in dd/mm/yyyy and some date are in yyyy/dd/mm
i want to convert dates which are only in yyyy/dd/mm --> dd/mm/yyyyhttps://i.stack.imgur.com/5SOV1.png
what is the way i can do this?
i tried concatenate(left()) and concatenate(middle()) and concatenate(right()) and then concate() to combine all this 3 different fields but then it is messing up the true date format i want that is dd/mm/yyyy as some dates are already in dd/mm/yyyy and i made used concatenate() for format yyyy/dd/mm
Let's say you have the input data in text format in column A. In column B you have the output in the equivalent date format (not text format). This is the proper way to handle dates. You asked to convert it to another text format, but I think it is better to have them as an Excel date type.
The following formula does that:
=LET(rng, A1:A4, texts, DROP(REDUCE("", rng, LAMBDA(acc,text,
VSTACK(acc, TEXTSPLIT(text,"/")))),1),
first, INDEX(texts,,1), second, INDEX(texts,,2), third, INDEX(texts,,3),
MAP(first, second, third, LAMBDA(a,b,c, IF(LEN(a)=4, DATE(a, c, b),
DATE(c, b, a))))
)
The formula returns an array, so there is no need to drag down the formula, useful for a large input data set. If you prefer to drag the formula down, then you can use the following formula:
=LET(text, TEXTSPLIT(A1,"/"), first, INDEX(text,1,1), second, INDEX(text,1,2),
third, INDEX(text,1,3), IF(LEN(first) = 4, DATE(first, third, second),
DATE(third, second, first))
)
Note: If you really want the dates in text format, then you can do it by replacing DATE function with: a&"/"&c&"/"&b and c&"/"&b&"/"&a respectively or to encapsulate DATE output with TEXT function, for example, TEXT(DATE(a, c, b), "mm/dd/yyyy") in the format of your preference.
Here is the output:
The previous solution works because we have a way to identify the year as a 4-digit number. If the year has 2-digits, then you need to build a logic to differentiate a year from a month or a day.
Because the data is in Excel date format (internally it is stored as a whole number), then you can format the date in the format of your preference without changing the data. In the screenshot, you see the dates in mm/dd/yyyy format. Having the data as a date type, you can use all Excel functionalities for working with dates. Having dates in text data type will have more limitations.
Here is the output using the UK locale and returning the dates in dd/mm/yyyy, but it is the same output data, just different visualization:
I better show you. This is how my list looks like:
And this is how I want it to be:
Basically, in the first picture I have different date ranges, for each date range I have a those two metrics, Sessions and Users and the final result should be a sort of explosion of all date ranges into single dates, considering that certain dates can be included in more than 1 date ranges (e.g. date 2017-08-12) is included in both first and second row.
And last but no least, the end date shouldn´t be counted.
Can someone help me out?
Thanks a million
A.
This is the outline of a solution:
Split each from/to date in your input table into its 2 constituent dates. You will need to use the string functions (LEFT, RIGHT and MID) to extract the numbers for the year, month and day values. These will still be strings of characters, so use the VALUE function to convert them to actual numbers and then use the DATE function to assemble them into a proper date value in Excel. (You may need to format your results using a date format, as Excel stores its dates as number of days since 01/01/1900, so 11/08/2017 is held in Excel as 42958.) Add as many helper columns as you need to your input table to achieve this.
Subtract 1 from each end date, this corrects the dates ranges so that the end date is included.
The first start date and the last end date define the range of output dates. So start your output table with the first date and in the cell below use a formula to add 1 to this date and copy the formula downwards until you get to your last possible output date.
To get the results for each possible output date, you need to find
which date ranges it belongs to. It belongs to a date range if it is
greater than or equal to the range's start date and less than or
equal to the end date. However, rather than comparing each output
date with individual start and end dates it is possible to compare
each output date with all the start and all the end dates at once. An expression such as A10>=E2:E7 generates an array of 6 elements with values
TRUE and FALSE according to whether A10 is greater than or equal to
E2, E3, E4, E5, E6 and E7 respectively. So, you can use this approach to generate an array of TRUE/FALSEvalues showing whether a particular output date is greater than or equal to (ie on or after) each range's start date. Similarly, you can get an array showing whether the same output date is less than or equal to (ie on or before) each range's end date.
The versatile SUMPRODUCT function can now be used to combine the arrays and the relevant sessions/users values from the input table to get the relevant values for the output date. For example, if the start dates are in E2:E7, the end dates in F2:F7, the sessions in B2:B7 and the output date in A10 then a sutable formula for determining the number of sessions to attribute to the output date would be =SUMPRODUCT(($A10>=$E$2:$E$7)*($A10<=$F$2:$F$7)*(B$2:B$7)). This formula could be copied to give results for all output dates and, assuming the input data for users is in C2:C7, it will also give the results for users if copied into the column adjacent to the sessions results. In this formula, the TRUE and FALSE values are effectively converted to 1 and 0, respectively.
A few points: (i) if you don't know how dates work in Excel then find out, it makes tasks such calculating the number of days between two dates or the date n days before/after a particular date extremely easy using simple arithmetic; (ii) don't confuse strings of text which look like dates with dates that can be manipulated arithmetically in Excel; (iii) I believe there are some errors in your example - 16/08/2017 is a date in two of your input ranges and should have results of (2,2) not (1,1) and 17/08/2017 is similarly in error.
I have used this approach in the illustration below and, to test its robustness, I have added an extra row of input data which has sessions different from users and which yields one date (19/08/2017) which does not match to any input range.
The output date range was generated as follows:
Cell A10: use formula =E2
Cell A11: use formula =1+A2
Cells A12, A13, ... copy formula in cell A11
In one column (E) I have values such as 2014-10-28 19:40:00+00:00. This is obviously date and time.
In my (F) Column I want to just use the date from that, so I've used the formula =LEFT(E:E,10) which worked nicely.
In my (G) Column I want the time, so I used =RIGHT(E:E,14) and it shows up with "19:40:00+00:00" which is what was expected.
Now I am trying to format the cells to have the time show up in a standard format of hh:mm. When I right click and select this format, nothing happens.
Is there a way to format the output of a formula or no?
RIGHT and LEFT return strings, return them to their numeric values using the VALUE formula
=VALUE(LEFT(...))
Should allow you to use custom formats again
If E1 contains:
2014-10-28 19:40:00+00:00
Then in G1 enter:
=MID(E1,12,5)
if your value in E is a date value, then =INT(E1) will extract the date, and =MOD(E1,1) will extract the time
If your value in E is text, then =INT(DATEVALUE(E1)) will extract the date, and =MOD(DATEVALUE(E1),1) will extract the time
Both will be in recognized formats for excel, and can then be formatted in any way you desire
I have an amount of data sort per date (e.g : 2013-12-12 10:51:51.000) and I want to display that data on a day-long plot : The plot will show the sum values or the % for each hours of the day from 0:00 to 23:59.
My problem is I don't know how to sort data "modulus day", since the date is store in one cell and so day and hours are not separates.
Thank you for your help
The Date in Excel cell is stored as a decimal, where integer part corresponds to Date and decimal to time after midnight, so for example 6/30/2014 9:00 is essentially equal 41820.38. Thus, the sorting should work perfectly fine: it will be using underlying numeric representation of Date and Time as explained above.
Pertinent to your further requirement, i.e. to sort only on time part (decimal) ignoring Date (integer) the solution might be as following: Assuming Date is stored in Column A (cell A1 for example), put a formula in Column B (cell B1)
=A1-INT(A1)
and extend it to entire range, then sort on Column B. Optionally, for your convenience, you can convert the cell format in Column B to Number (to view just decimal part).
Rgds,
I'm trying to match a date against an array. However, I notice my date is evaluated as an integer.
Instead of =MATCH(20/02/2014;B1:B21;1) it becomes =MATCH(41690;B1:B21;1); and I'm getting an #N/A as a result!
How to get this rectified?
Thanks!
Make sure that dates in your lookup column are actually dates (i.e. 5-digit decimal values in fact, but not text).
Use a formula like this:
=MATCH(DATE(2014,2,20),B1:B21,1)
This is because your lookup range is not formatted as Date, because in whatever format you write a date (dd/mm/yy or mm/dd/yy or yy/dd/mm) dates should match if written as date.