Contenate while keeping leading zero - excel

I have an Excel spreadsheet in which the date of certain events is stored in three columns: year, month, and day.
Year
Month
Day
1734
04
08
1750
11
10
I set the format of the cell to 'custom' so as to show the leading '0' which I want to maintain. I now want to concatenate the information in these cells so that it shows the date as follows YYYY-MM-DD. I'm using this formulate to achieve that:
=CONCAT(B2, "-", C2, "-", D2)
Annoyingly, however, it doesn't maintain the leading zero (the result is: 1734-4-8 and 1750-11-10, respectively). Does anyone know how to concatenate the data from these cells while maintaining the leading zero?

Cell formatting only changes appearance, but doesn't alter value. Even if it looks like 04 it still is 4 as value.
Use TEXT:
=CONCAT(B2,"-",TEXT(C2,"00"),"-",TEXT(D2,"00"))
or
=TEXTJOIN("-",,B2,TEXT(C2,"00"),TEXT(D2,"00"))

Related

Convert text date/time to as date time format in excel

Data is extracted from the application. There is a text representation of data/time as
"Wed Nov 30 2022 09:30:00 GMT+0530 (India Standard Time)" (in text)
I am required to format this column as MS data/time type, instead of text
First:
Tried custom format.. but didn't work.
not able to teach "Wed" and "GMT..." part
Second:
Tried to break the words as
=MID(A1,5,20) [it gives "Nov 30 2022 09:30:00" ]
and then apply.
=TIMEVALUE(TEXT(RIGHT(B1,8),"HH:MM:SS"))
It worked and excel was able to understand it in time format as9:30:00 AM
But, when I applied similarly the Date format as
=DATEVALUE(TEXT(LEFT(B1,11),"mmm dd yyyy"))
It gave a Value error, not sure what to do next
Finally:
Is there a way to do it in one go?
the entire column can be formatted as a valid date and time.
I took inspiration from:
[question]: Convert text date/time to a real date time in excel
[blog]: https://support.microsoft.com/en-us/office/format-numbers-as-dates-or-times-418bd3fe-0577-47c8-8caa-b4d30c528309
Kindly advise
There are many ways to do it, perhaps for now, I have tried this one,
• Formula used in cell B1
=LET(_string,TEXTSPLIT(MID(A1,5,20),," "),
_date,DATE(INDEX(_string,3),MONTH(INDEX(_string,1)&1),INDEX(_string,2)),
_time,TIMEVALUE(INDEX(_string,4)),
_date+_time)
Another way,
• Formula used in cell C1
=DATEVALUE(SUBSTITUTE(LEFT(MID(A1,5,20),11)," ",", ",2))+RIGHT(MID(A1,5,20),8)+0
DATEVALUE() wrapping not required actually,
• Formula used in cell C1
=SUBSTITUTE(LEFT(MID(A1,5,20),11)," ",", ",2)+RIGHT(MID(A1,5,20),8)
Use LET() to make it more readable,
• Formula used in cell C1
=LET(_extract,MID(A1,5,20),
_datepart,LEFT(_extract,11),
_timepart,RIGHT(_extract,8),
SUBSTITUTE(_datepart," ",", ",2)+RIGHT(_timepart,8)+0)
One more sleek way is using TEXTBEFORE() & TEXTAFTER()
• Formula used in cell D1
=SUBSTITUTE(TEXTBEFORE(TEXTAFTER(A1," ")," GMT")," ",", ",2)
Note: Since in Excel Date and Times are stored as number this will return as a number, The integer portion of the date serial number represents the day, and the decimal portion is the time, hence format it accordingly as per your need or regional settings.

How do I return a blank if there is no data on a separate sheet?

I want data in F16 sheet STATISTICS to only be present when there is a W in column P on sheet TRADE LOG between the dates 01 Feb 2021 and 28 Feb 2021.
If there is no WI want F16 to return a blank.
This is the formula I am currently using:
=IF(ISBLANK(INDIRECT(CONCATENATE("E",ROW()))), "", COUNTIFS('TRADE LOG'!P:P,"W",'TRADE LOG'!B:B,">="&DATE(2021,2,1),'TRADE LOG'!B:B,"<="&DATE(2021,2,28)))
I anyone could suggest any tweaks that would allow me to do this I would be grateful.
place the following formula in F16 and replace "Data" with the formula or data you want displayed when there is a "W" in your hard coded date range. Do note that the "W" in the P column is not case sensitive.
=IF(COUNTIFS('Trade Log'!P:P,"W",'Trade Log'!B:B,">="&DATE(2021,2,1),'Trade Log'!B:B,"<="&DATE(2021,2,28)),"DATA","")
You may also want to look at placing the month you want to check or date range as a cell reference instead of a hard coded date, but you will need to make that decision based on your needs.
In order to display the "W"s within date criteria, replace "Data" with the part of the formula you used to make the count in the first place.
COUNTIFS('Trade Log'!P:P,"W",'Trade Log'!B:B,">="&DATE(2021,2,1),'Trade Log'!B:B,"<="&DATE(2021,2,28))
When substituted into the original formula it will look like the following:
=IF(COUNTIFS('Trade Log'!P:P,"W",'Trade Log'!B:B,">="&DATE(2021,2,1),'Trade Log'!B:B,"<="&DATE(2021,2,28)), COUNTIFS('Trade Log'!P:P,"W",'Trade Log'!B:B,">="&DATE(2021,2,1),'Trade Log'!B:B,"<="&DATE(2021,2,28)),"")
Alternate Approach
You could also just use the countifs formula and use custom formatting for the cell so that a zero value is displayed as nothing or space.

How to auto populate the next week in excel

I am making an on-call schedule in excel and I can't for the life of me find an easy way to populate the dates. For example, someone is on call from Monday to Sunday, January 2nd - January 8th. Then the next person is on call from January 9th - January 15th. I am trying to figure out a way or formula to just "Drag" down the column and it input the next 7 day range. I have tried input the start date and end date in a separate cell, then using concatenate but it returns the date number in excel (forgot what its called). I also tried =(A1&" - "&B1) but that returns the same 5 digit number.
Any help or pointers are greatly appreciated!
Previous date + 7
If you have genuine dates, say in cells A1 "start date" and B1 "end date":
Jan 2 Jan 8
Then the next line will be
=A1+7 =B1+7
Verify Dates
To see, if the "Dates" you entered are realy dates excel can work with like that, apply "General formatting" to the A1 and B1 cells. If the resulting value is an Interer or a Decimal number, you are golden. If the resulting value did not change, you have a text and you need to apply different approach.
Perhaps you are looking for this:
=TEXT(A1,"d-mmm")&" - "&TEXT(B1,"d-mmm")
The formatting specification can be copied from the formatted cell properties.

Identifying date in text file While date is incorrectly formatted

I need to extract the date from C2 and find the difference between the date in c2 and A1
The date is formatted as "Jul, 18 2015", any ideas? EDIT the database has a different amount of text per cell. Is there away around this so that i can apply the formula to every cell and pull the day/month/year?
you are going to need to go through a series of string manipulation and date time functions. Lets start by assuming your string is in the C2 cell. In order to do this we are going to work from the largest unit (years) to the smallest unit (days). You can do it in any order as it will all be lumped into once formula, but for the breakdown of steps its good to have an order.
Step 1) PULL OUT THE YEAR
=MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4)
That will give us the last 4 characters of the string after the second space which in this case is the year.
Step 2) PULL OUT THE MONTH
=MONTH(DATEVALUE(MID(C2,2,3)&"-"&1))
that looks at second character and pulls out the string 3 character long which is your month. It then converts it to a format that excel tends to recognize as a date short form by adding a - and the digit 1 to it. So in your case if would look like Jul-1. Datevalue converts this to an excel date serial, which we then pull back and grab the month from and in your case that is 7
If the above formula does not work for you it could be due to regional settings. If that is the case you can use the following:
=MATCH(MID(C2,2,3),{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},0)
If you use this alternat formula , be sure to adjust the final equation accordingly.
Step 3) PULL OUT THE DAY
=TRIM(MID(C2,FIND(" ",C2)+1,2))
So the above formula finds the first space and then starts pulling then next 2 characters after it. Now since I do not know if the first of the month is 01 or just 1, it may wind up grabbing the space after the 1. The trim function removes excess spaces.
Step 4) BUILD THE DATE
The DATE function in excel requires the YEAR, MONTH, and DAY and converts those values in to the excel date serial. In this case we will convert:
=DATE(year,month,day)
to the following by substituting our equations from above:
=DATE(MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4),MONTH(DATEVALUE(MID(C2,2,3)&"-"&1)),TRIM(MID(C2,FIND(" ",C2)+1,2)))
The final touch is to ensure your cell is formatted as date and not General or some other format which will result as the date being displayed in an integer format.
Now assuming you date in A1 is in Excel format, you would simply add A1- to the front of the last formula to give you:
=A1-DATE(MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4),MONTH(DATEVALUE(MID(C2,2,3)&"-"&1)),TRIM(MID(C2,FIND(" ",C2)+1,2)))
Now, if A1 is also in quotes like the C2 formula, repeat the formula for stripping the date out of C2 but use A1 as the reference and substitute it in for A1 in the last formula to give:
=DATE(MID(A1,FIND(" ",A1,FIND(" ",A1)+1)+1,4),MONTH(DATEVALUE(MID(A1,2,3)&"-"&1)),TRIM(MID(A1,FIND(" ",A1)+1,2)))-DATE(MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4),MONTH(DATEVALUE(MID(C2,2,3)&"-"&1)),TRIM(MID(C2,FIND(" ",C2)+1,2)))
FORMULAS USED
Text/String Functions
MID
FIND
TRIM
Date/Time Functions
DATE
DATEVALUE
MONTH

Excel will not read date

I've tried a million things to get Excel to read a date that is being pulled by this formula:
=(LEFT(VLOOKUP(C7,'Input Engagement Status'!C:M,9,FALSE),11))
I use LEFT because the cell I'm referencing is storing two dates simultaneously. The output is "mmm dd yyyy".
I have tried text to columns, but the formula is being pulled apart rather than the date that it reads for.
I have tried custom formatting to create a new date format for "mmm dd yyyy". I have changed from general, to numbers, to text, and I am out of solutions at this point. Any help would be greatly appreciated.
A way to illustrate the differences is with a date on the worksheet. Excel treats dates as 1 for every day past Dec 31, 1899. Today happens to be 42,192 (or 42192 as Excel sees it).
If you put =TODAY() in a cell (e.g. A1) and use =RIGHT(A1, 2), the A1 cell probably shows 07/07/2015 but the underlying value is 42192 so the RIGHT(A1, 2) is going to return 92. Format the cell so it displays Tuesday, July 7, 2015 and RIGHT(A1, 2) is still going to return 92.
If you have two dates in the same cell separted by a space or other delimiter as a text string then you should be able to pull the first 11 characters from the string value and convert it back to a date with the DATEVALUE function.
Using this data in a single cell (A1):
Jul 07 2015 Jul 15 2015
Use the SUBSTITUTE function to insert a comma so that DATEVALUE will resolve the date correctly.
=DATEVALUE(SUBSTITUTE(LEFT(A1, 11), " 20", ", 20"))
=DATEVALUE(SUBSTITUTE(RIGHT(A1, 11), " 20", ", 20"))
Format the result as a date. The above will return 42,192 and 42,200 (the number of days since Dec 31, 1899). Format as a date to get something like 07/07/2015 and 07/15/2015.
You should be able to transcribe your VLOOKUP function into that simple example.

Resources