Combine a number with a date without showing 'year' as 1900 - excel

I'm trying to convert a number and date together in Excel 2013 as one number. Example:
Cell A1 contains a number 123456 and B1 contains a date 02/07/1976.
I need to combine both so A1 reads 12345602071976 (without the slashes in the date).
Instead, I'm getting 1234561900 and was getting a weird error that showed something like...123456+16? I believe I need to insert blank columns and separate out the date and then create a formula to combine everything but I'm not sure how to do that.

Please try:
=A1&RIGHT("0"&DAY(B1),2)&RIGHT("0"&MONTH(B1),2)&YEAR(B1)

Here you go:
=A1&TEXT(DATEVALUE(B1),"mmddyyyy")
Note: assumes your date is text. If the date in B1 is actually a true Excel date, then this:
=A1&TEXT(B1,"mmddyyyy")
Note: if you want the days to come before the months then reverse the mmdd to ddmm.

Related

How to extract year from an excel cell containing an old date?

When I have a date like 2/12/2022 in a cell in an excel document (say in the cell A1),
=year(A1)
gives 2022, but this does not work for a date like 2/12/1875.
Indeed it returns #Value!.
2/12/1875 is before the beginning of the date system in Excel.
To see the beginning, as per your system, write 1 and format as a date:
In general, using the =YEAR() formula is not possible before the beginning of the first serial number, thus you should resort to other options. Like this one:
=RIGHT(A2,4)
or a more complicated one, that gives the last element in A2, separated by "/":
=RIGHT(A2,LEN(A2)-SEARCH("/",A2,SEARCH("/",A2,SEARCH("/",A2)+1)))
Try this-
=TAKE(TEXTSPLIT(A1,"/"),,-1)

Change date in excel

I am trying to change the date format of my cells in excel to another date format. Currently it is in this format: apr, 10, 2017 01:58:24 PM. I would like to have it in a normal format like dd-mm-yyyy without the time, but I can not get it to work with the formatting in excel.
Thanks in advance,
Kester
You could use this:
=(MID(A2,FIND(",",A2)+2,FIND(",",SUBSTITUTE(A2,",","#",1))-FIND(",",A2)-2)&"-"&LEFT(A2,FIND(",",A2)-1)&"-"&MID(A2,FIND(",",SUBSTITUTE(A2,",","#",1))+2,LEN(A2)))*1
Which is basically a bit of string manipulation (and some substitution of , to # to help) to put it in the generic format 'd-m-y h:m:s t', which excel understands, then multiply the string by 1 to force into a number (in this case 42835.58222); which you only have to format as date (important!):
Edit: Per comments, the first comma doesn't actually exist, so the revised formula:
=(MID(A2,FIND(" ",A2)+1,FIND(",",A2)-FIND(" ",A2)-1)&"-"&LEFT(A2,FIND(" ",A2)-1)&"-"&MID(A2,FIND(",",A2)+2,LEN(A2)))*1
With data in A1, in B1 enter:
=DATE(MID(A1,10,4),MATCH(LEFT(A1,3),{"jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"},0),MID(A1,6,2))
and apply desired formatting:
(this results in a genuine Excel date that can be used in sorts, calculations, etc.)(this assumes that the day field is always two digits)(if your month list is in a language other than English, edit the month list)

Extract date out of cell with date and time

I have a cell G4 with date and time in a format (Text string):
1/29/2020 1:34:24 PM
I need to convert it to DATE formatted cell. How to do that?
I have tried to get numbers and convert them to DATE with this formula:
=DATE((MID(G4;SEARCH("/";G4)+4;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)+2));(MID(G4;SEARCH("/";G4)+1;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)-1));(LEFT(G4;FIND("/";G4;1)-1)))
So:
I am extracting year:
=MID(G4;SEARCH("/";G4)+4;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)+2)
Month
=MID(G4;SEARCH("/";G4)+1;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)-1)
Day
=LEFT(G4;FIND("/";G4;1)-1)
I am getting as a result:
1.5.2022
I need it as it is now, but output should be 29.1.2020 in this case. Later I want to get day difference two that way formatted dates. Is it possible to do it with formula without performing any other cell formatting operations?
EDIT:
I got it working, the only problem is:
How to extract number (year) after third "/"? My current formula is not correct:
=MID(G4;SEARCH("/";G4)+4;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)+2)
It does not function correct in this case:
2/5/2020 12:21:05 PM
EDIT:
I did it this way (I also had to minus G2 - F2, to get days difference):
=IFERROR(DAYS(MID(G2;SEARCH("/";G2)+1;SEARCH("/";G2;SEARCH("/";G2)+1)-SEARCH("/";G2)-1)&"."&LEFT(G2;FIND("/";G2;1)-1)&"."&MID(G2;FIND("/";G2;FIND("/";G2)+1)+1;4);MID(F2;SEARCH("/";F2)+1;SEARCH("/";F2;SEARCH("/";F2)+1)-SEARCH("/";F2)-1)&"."&LEFT(F2;FIND("/";F2;1)-1)&"."&MID(F2;FIND("/";F2;FIND("/";F2)+1)+1;4));"")
You probably need to replace an order of day.month.year and "." to "/" if you are using different date setting (region). I have one setup, so this seems to work.
FYI DATES in excel are stored as integers. They represent the number of days since 1900/01/01 with that date being 1. TIME is stored as a decimal representing fractions of a day or 24 hours. 0.5 represents noon. 24:00 is not an officially supported time in excel, but will work with some functions.
The DATE Formula is looking for three arguments representing YEAR, MONTH, DAY in that order.
DATE(Year, Month, Day)
You need to pull the text from your string representing these values. I find it easiest to pull each one individually in its own cell to ensure the part of the formula is working first then copy and past that part into the DATE formula so the whole calculation in the end can be performed in one cell.
YEAR
To get the year use the following formula:
MID(G4,FIND("/",G4,FIND("/",G4)+1)+1,4)
MONTH
To get the month use the following formula:
LEFT(G4,FIND("/",G4)-1)
DAY
To get the day use the following formula:
MID(G4,FIND("/",G4)+1,FIND("/",G4,FIND("/",G4)+1)-FIND("/",G4)
COMBINED FORMULA
Place the above formulas into the date formula as follows:
=DATE(MID(G4,FIND("/",G4,FIND("/",G4)+1)+1,4),LEFT(G4,FIND("/",G4)-1),MID(G4,FIND("/",G4)+1,FIND("/",G4,FIND("/",G4)+1)-FIND("/",G4)-1))
Note the only cell reference in the formula is G4. The results of the formula are not in an Excel Date format. Change the formatting of your cell to meet your needs. In your case I would apply a custom cell format of d.m.yyyy
If you have TEXTJOIN,
=TEXTJOIN("/",TRUE,INDEX(FILTERXML("<a>,<b>"&SUBSTITUTE(SUBSTITUTE(TEXT(A1,"dd/mm/yyyy hh:mm:ss"),"/","</b><b>")," ","</b>",1)&"</a>","//b"),N(IF({1},{2,1,3}))))
Depending on your version it may need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.
the reason the second did not work is that Excel actually changed it to a date and a date is a double, not text. So there are no / in the data. so we need to force back to the incorrect string.
Those for whom the TEXTJOIN function is not available can use this:
=DATE(FILTERXML("<DATA><A>" & SUBSTITUTE(SUBSTITUTE(A1;"/";"</A><A>");" ";"</A><A>") & "</A></DATA>";"/DATA/A[3]");FILTERXML("<DATA><A>" & SUBSTITUTE(SUBSTITUTE(A1;"/";"</A><A>");" ";"</A><A>") & "</A></DATA>";"/DATA/A[1]");FILTERXML("<DATA><A>" & SUBSTITUTE(SUBSTITUTE(A1;"/";"</A><A>");" ";"</A><A>") & "</A></DATA>";"/DATA/A[2]"))

Date formula not working

I have columns containing separate values for Day, Month and Years which are formatted as general and contain no other formatting or formulas.
I'm trying to combine them using the =DATE formula in order to get proper date values, but it is giving me a #VALUE! error.
What am I doing wrong?
Just use:
=DATE(C1,MONTH(DATEVALUE(A1&" 1")),B1)
Where you can convert month name to month value using MONTH(DATEVALUE(A1&" 1"))
Use 3 instead of writing March in column A.
Also check if your date format is set to DATE(year,month,day) in Home > Format > Format Cells>Date.
Ref: https://support.office.com/en-us/article/DATE-function-e36c0c8c-4104-49da-ab83-82328b832349

Can I use the CountIf function to count the # of cells containing certain date keywords?

I have a set of data that looks something like this:
11/8/12 5:20
11/7/12 15:57
11/7/12 13:51
11/7/12 10:47
11/7/12 8:00
Just in Excel, I want to be able to count the number of rows with 11/8/12, and the number of rows beginning in 11/7, etc. I have a pretty long list of dates and times, but I'm only interested in the dates.
I tried =COUNTIF(A1:A235, "<11/8/12 5:20") to get everything before 11/8, but obviously this doesn't work because I need to type in the time. Does anyone know how to:
1) make the timestamp irrelevant?
2) somehow search for rows that "contain" a certain date value and count up the rows that contain that value?
You can insert in a cell e.g. F7 the date which should be used
and then your formula will look like this
=COUNTIF(E8:E12;"<"&F7)
And then in case that your F7 will contain 11/7/12 14:00 the countif will return 3
NOTE: expecting the british date 11/7/12 is dd/mm/yy
EDIT: Date function
When I've seen another answer, I would like to show another approach, which is culture safe. Whenever we will put some strings representing dates, it could happen that a collague has different regional settings (e.g. British dd/mm/yy vs US mm/dd/yy)
That's why I placed the date into separated cell, representing the Date regardless of the culture. If that all have to be placed inside one cell, the correct approach is to use Date function
=COUNTIF(E8:E12;"<"&DATE(2012;7;11)+TIME(14;0;0))
In Excel dates are integers and the time is a fractional value so you can simply count between one date and the next (date +1) to get everything on a single date, e.g. for everything on 11/7
=COUNTIF(A1:A235, ">=11/7/12")-COUNTIF(A1:A235, ">="&"11/7/12"+1)
or in Excel 2007 or later you can use COUNTIFS
=COUNTIFS(A1:A235, ">=11/7/12",A1:A235,"<"&"11/7/12"+1)
for either one you can use a cell reference with the date as Radim suggests, i.e. with date in B1
=COUNTIFS(A$1:A$235,">="&B1,A$1:A$235,"<"&B1+1)
With that last version you can simply list all your dates in B1 down, and then use the formula in C1 copied down to get counts for each date

Resources