Advanced Date Formatting

blemley

New Member
Joined
Nov 2, 2009
Messages
4
Hi guys, I have a rather unique question. I have searched the forms, but no luck. Hopefully you all can help.

I have a course schedule with start date in column A and end date in col B formatted as mm/dd/yyyy. I have written the following function to display them as a date range in column C:

=text(A1, "mmm dd")&" - "&text(B1, "mmm dd")

This outputs a the date as: Jan 12 - Jan 14.

What I would like to do is take this a step further. If the end date and the start date are in the same month, I only need to display the month in the start date. For example: Jan 12 - 14. However, if the end date is in the next month, I need to display both month. Example: Mar 30 - April 01.

Beyond that, is there a way that I can have all dates 01-09 display as "1, 2, 3, 4, 5, 6, 7, 8, 9" without the preceding zero? Example: Mar 30 - Apr 1.

Thanks in advance!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Welcome to the board.

Maybe:

=TEXT(A1, "mmm d")&TEXT(B1, IF(A1=B1,"",IF(MONTH(B1)=MONTH(A1)," - d"," - mmm d")))

Which will also just display Jan 12 if A1 and B1 were to be the same date.
 
Upvote 0
Welcome to the board..

1st question - seems more trouble than it's worth. But I think this would work

=text(A1, "mmm dd")&" - "&text(B1, IF(Month(B1)=Month(A1),"dd","mmm dd"))



2nd question, that's easy. Just use d instead of dd in your date format

=text(A1, "mmm dd")&" - "&text(B1, IF(Month(B1)=Month(A1),"dd","mmm dd"))
change to
=text(A1, "mmm d")&" - "&text(B1, IF(Month(B1)=Month(A1),"d","mmm d"))

Hope that helps..
 
Upvote 0
Ciao,

=IF(MONTH(A1)=MONTH(B1),TEXT(A1, "mmm d")&" - "& TEXT(B1,"d"),TEXT(A1, "mmm d")&" - "& TEXT(B1,"mmm d"))

Hope it helps you
 
Upvote 0

Forum statistics

Threads
1,215,049
Messages
6,122,864
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top