How to subtract dates in Excel with different date formats? - excel

I want to subtract 2 dates in Excel but the problem is they have different date formats.
So... my first date is something like this 18.09.2011 (DD.MM.YYYY) and the second one is something like 9/15/2011 (MM/DD/YYYY). So how can I subtract these two dates? Because DAY(cell of date one) - DAY (cell of date 2) won't work.
Thanks!

If your dates are really entered as dates you can use them in any kind of calculation, as a date really is stored as a numeric value. Displaying one date in "MM/DD/YY" and the other one in "DD.MM.YYYY" doesn't make a difference. Try to format the cells as "General". Does the display change to a number (e.g. 40801 for today) you're fine. If your dates are entered as strings you may want to convert them into dates first - see this post

Related

Excel - count days between two dates per year

I am trying to get the number of days per year between two dates.
The results should look somehow like the following picture
The range between the 2 dates in the 2021 year has 301 days and in the 2022 year has 94 days.
Put this in C2 and copy over:
=MIN(DATE(C1,12,31),$B$2)-MAX(DATE(C1,1,1),$A$2)
Your question isn't entirely easy to understand but what you don't know is in plain sight: Excel represents dates as integer numbers where Jan 1, 1900 is the first day (= 1) and all days from then till now have a unique number. Today is 44261. Tomorrow will be 44262.
Therefore the difference between dates equals [End date] - [Start date], where only one of these two dates is included in the count. [Tomorrow]-[Today] = 1, not 2.
When a worksheet cell is formatted as General Excel will automatically change that format to whatever Excel thinks you have probably entered. If you enter what Excel recognizes as a date the cell format will be changed to Date and if the way you entered the date was by function, such as =TODAY() the cell will display "6/3/2021" using the date format specified in your Windows International settings.
But if you manually change the cell format back to General or Number the display will change to 44262. That's the way you can test if your cell contains a "true" date, with which you can do calculations, or a "fake" date, which is just a text string which is nice to look at but otherwise useless.

Sorting excel table by dates of events (sometimes 1day sometimes dd1.-dd2.mm.yyyy)

I have to sort a table of events by date, what is working fine as long as I have only singe day events. But as I am having as well events going over several days it isn't working anymore.
I guess the main problem is, that excel doesn't recognize the dd. - dd.mm.yyyy as a date.
(I am using the German dd.mm.yyyy format and that is working fine with the single day dates, but I wouldn't mind using a different format)
01. - 04.06.2016
21. - 22.04.2016
25.5.2016
10.10.2016
28.11. - 02.12.2016
the single dates are right-aligned (recognized as dates) the from-till dates are left-aligned (not recognized)
The dd.mm.yyyy format will be stored as a date which sorts correctly. The dd. - dd.mm.yyyy date ranges will be stored as text and sorted based on the characters.
You need to either split date ranges into 2 columns with the starting date in the first column along with the single dates; or change the format of the dates and ranges.
To keep everything in one cell, you would need to first change cells to Text formatting and enter everything as:
yyyy.mm.dd
yyyy.mm.dd - .dd

Converting month number from full date cell into text month in Excel

So I have a pretty long column with name dates and hours, like this:
14/01/2017 03:30
(They are DD/MM/YYYY HH:MM)
I need to get the month number and show it as text, like January, February, and so on.
If I format the destination cell as 'MMM' all the column cells show January even if the given month is 2, 3, or let's say 12. I also tried the formula =TEXT(L2,"mmmm") (since the given info come from column F.
Any ideas?
sounds like your date and time are stored as text and not in excels serial date format. You can test this by changing the format of the cell to general and seeing if anything happens if nothing changes then its text. another way would be to use the formula =istext(A1) where A1 is a cell with a date in it.
Now ASSUMING you do have dates in text format, I would suggest converting them to excels date serial. There are numerous ways of doing this. I will show you one way.
This will strip each component of the text out and then recombine it. We will assume your date in is A1
Strip out the year
=MID(A1,7,4)
Strip out the month
=MID(A1,4,2)
Strip out the day
=LEFT(A1,2)
Now to recombine it:
=DATE(MID(A1,7,4),MID(A1,4,2),LEFT(A1,2))
That will give you the date in an integer format that excel can then turn around and display as needed.
In order not to lose the time component you should strip that part off as well and combine it with the date. Remember the date is an integer, and the time is everything after the decimal. Think of time as a fraction of a day.
To get time out use:
=RIGHT(A1,5)
and to convert it to excel time:
=TIMEVALUE(RIGHT(A1,5))
and to get the two together, simply add:
=DATE(MID(A1,7,4),MID(A1,4,2),LEFT(A1,2)+TIMEVALUE(RIGHT(A1,5))
The key part to this whole thing is you will need to format that cell to display what you want. you can either choose a preformatted style from the drop down menu, or you can apply custom formatting. Setting the custom format to MMMM should display just the full name of the month.
IF you actually need the text of the month and not just the format, then you could use the formula from your question:
=TEXT(<insert appropriate formula from above>,"mmmm")
Try using MID to get the month only, then TEXT():
=TEXT(MID(A1,SEARCH("/",A1)+1,2),"MMMM")

Formula to convert a cell formatted in MM/DD/YYYY , to numeric month.

Is it possible to convert the standard excel format (MM/DD/YYYY) to just the month? I have column B that has a date format &column V where I have the month. I have check the internet/stack overflow, but have only found conversions for changing the format of the date.
you mean like the MONTH() formula?:
=MONTH(B1)
If the date is stored as an excel serial, to display just the month without losing the potential other information such as year, day, and time that might be stored with it, you are usually better off reformatting the display of the cell.
If you set the format of the cells to General and the numbers change you know you have your date in an Excel format. If they do not change you have them as a string.
Select custom format for the cell format and go to the area when your can type in display formats and set it either to
m or mm - for numbers to be displayed. The later will give you a proceeding 0 for single digit months.
mmm - for the first three letters of the month.
mmmm - for the full spelling of the month.
If you need to make comparisons of the month from a full date, use the formula macro man listed in a manner like:
=Month(B1)=Month(V1)
That will display true if the months for the dates in both A1 and V1 are the same.

SUMIF YYYY-MM-DD = TODAY?

I have fields that look like, and has to look like this:
YYYY-MM-DD G/G
YYYY-MM-DD U/G
YYYY-MM-DD G/U
YYYY-MM-DD U/U
I want to show in a cell, the SUM of the dates that correspond to the date today is. Is this possible, and how? Like:
Done today: XX
Taking a guess, assuming:
You have a column of dates and a separate column of other data.
The dates are in ColumnA.
Since your example shows a single result, the other data is irrelevant for current purposes.
Dates are date/time indices, not text strings.
You don't want to sum dates (adding the day war broke out to the date you were born is nonsensical) but count them.
Then perhaps:
=COUNTIF(A:A,TODAY())
which, depending upon locale, may need to be:
=COUNTIF(A:A;TODAY())

Resources