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:
Is there a method to convert these column in data format? (gg/mm/aaaa hh:mm:ss)
DATE : 20220601 >>>> 2022/06/01
HOUR : 3047 >>>>> 00:30:47 (hh:mm:ss)
I have serious problem with column B, i need to convert it in (hh:mm:ss). Someone can help me?
The final result should be "01/06/2022 00:30:47"
If you have Excel 365 you can use this formula:
=LET(HourText,TEXT(B2,"000000"),
DateText, A2,
HourFinal,TIME(LEFT(HourText,2),MID(HourText,3,2),RIGHT(HourText,2)),
DateFinal, DATE(LEFT(DateText,4),MID(DateText,5,2),RIGHT(DateText,2)),
DateFinal + HourFinal)
It first takes the text-hour and the text date.
Text hour is formatted as hhmmss - to have the zeros for hour if missing. Then it is easier to return the true hour.
Adding both values (date + hour (yes this is mathematical addition) returns the date.
You can then format the date as you like, e.g. as dd/mm/yyyy hh:mm.ss
Try-
=TEXTJOIN("/",TRUE,MID(A1,{1,5,7},{4,2,2})) & " " & TEXTJOIN(":",TRUE,MID(RIGHT("00"&B1,6),{1,3,5},{2,2,2}))
For pure date value use below function then use cell format to show your desired date/time format.
=DATEVALUE(TEXTJOIN("/",TRUE,MID(A1,{1,5,7},{4,2,2})))+TIMEVALUE(TEXTJOIN(":",TRUE,MID(RIGHT("00"&B1,6),{1,3,5},{2,2,2})))
Here is an easy alternative solution, using the TEXT() Function with a Custom Formatting for Dates 0000\/00\/00 while for Times 00\:00\:00
• Formula used in cell C2
=TEXT(A2,"0000\/00\/00")+TEXT(B2,"00\:00\:00")
So, the first part of the TEXT() function returns & converts the Numbers into Dates, while the second part returns & converts the Numbers into Times, and as we know that Dates & Times are stored as Numbers in Excel, so the Integer part which represents the Dates and the Decimal which represents Times, when added to together returns a Number with Decimals using the TEXT() Function.
Hence if the cells are not formatted before then please select the cell or range and press CTRL+1 --> Format cells Dialogue Opens --> Number Tab --> Category --> Custom --> and type by removing General as dd/mm/yyyy hh:mm:ss or as per your region it will be gg/mm/aaaa hh:mm:ss
Note: For more inspiration on converting Dates when shown like those numbers, you can refer this link, I have shared a whole lot of alternatives.
CHANGE THE DATE FORMAT
I'm trying to translate a machine-learning model into excel, so that data analysts could play with it interactively.
I'd like to transform a categorical variable into dummy representation:
WeekDay
Monday
Thursday
to
WeekDay
{1,0,0,0,0,0,0}
{0,0,0,1,0,0,0}
Using excel arrays.
I tried this:
={INT(A1="Monday"),INT(A1="Tuesday"),INT(A1="Wednesday"), ...}
However, for some reason, excel doesn't accept forumlas in array expressions.
This approach does work, but it is problematic - since it does not allow combinig multiple arrays into one
=IF(A1="Monday", {1,0,0,0,0,0,0}, IF(A1="Tuesday", {0,1,0,0,0,0,0}, ....))
Also, it's super ugly
Any ideas ?
To get your array you can use INDEX like this:
INDEX(IF(TEXT(ROW($2:$8),"dddd")=A1,1,0),0)
This returns a vertical array.
to return a horizontal array use:
INDEX(IF(TEXT(COLUMN($B:$H),"dddd")=A2,1,0),0)
I have spilled the results of the array in the photo below:
If one has the Dynamic Array Formula SEQUENCE the ROW and COLUMN can be replaced with:
SEQUENCE(7,,2)
and
SEQUENCE(,7,2)
Respectively
I am not sure what the end goal is, but I would suggest instead of an array (again, assuming you are not utilizing VBA, and even if you are, this is very possible with Case functions):
Use the formula =Weekday(Cell,different return type for which day should = 1)
If you were to use the actual date (e.g. 5/1/2020), display it through custom formatting with only the day of the week (typically data analysis will already have the full date),
Cell Value A20 = "5/1/2020", format display Long Date - "Friday, May 1, 2020"
cell referencing with formula '=WEEKDAY(A20,1)' = 6
cell referencing with formula '=WEEKDAY(A20,2)' = 5 (is this similar to {0,0,0,0,1,0,0} enough for you to use?)
if using VBA, you could define a range with logic to turn this into {0,0,0,0,1,0,0}
Hope this helps.
I would like to filter my data in spotfire using a date range formula, like this Date > '2020-05-01'
May i know how to write this date rangr using spotfire formula?
The correct syntax would be : [ColumnName] > Date('2020-05-01) This will take your string of '2020-05-01' and convert it to a date which can be used to compare to your date column. This can be used in data limiting expressions in a visual , calculated column or anywhere else an expression can be used.
I am completely new on Excel and trying to do a measurement.
Which is finding the middle age of a END DATE - START DATE/2
Which should be retun as a date format.
I am using this query --
=DATE([End Date]-[Start Date])/2)
Could anyone can correct me with this query please.
You actually don't want to use the DATE formula as has three parameters. What you want to do is (END_DATE-START_DATE)/2 + START_DATE and have the cell containing that have the 'Date' format.