Dates

How_Do_I

Well-known Member
Joined
Oct 23, 2009
Messages
1,831
Office Version
  1. 2010
Platform
  1. Windows
Could anyone help me out with these please. I have two formats of dates, the 1st format is in B2 and is monthly... I'm after the returns in C2 and D2 which are the first and last days of the respective months. The 2nd format is dates that need the format altering to day / month / year. I'm not bothered if helper columns are added to achieve the desired solution...

DateStart DateEnd Date
1st Format1916/01-1917/11
01-Jan-1916​
30-Nov-1917​
2nd Format1915/12/24-1916/07/22
24-Dec-1915​
22-Jul-1916​
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Not enough information.

1916/01 - there is no day in this field
1917/11 - there is no day in this field either

You are implying for the missing day information that
Start Date, e.g. 1916/01 - result required, assume first day of the month
End Date, e.g. 1917/11 - result required, assume last day of the month

So given the format
1916/01-1917/11

The first of the day of the month should be added to the start date
and the last day of the month should be added to the end date

Will this ALWAYS be the case?
 
Upvote 0
Assuming it is ALWAYS the case


Start date
=IF(LEN(B1)=15,(LEFT(B1,7)&"/01")+0,LEFT(B1,10)+0)

End Date
=IF(LEN(B1)=15,(EOMONTH(RIGHT(B1,7)&"/01",0))+0,RIGHT(B1,10)+0)

where B1 is the date string
 
Upvote 0
Hi How_Do_I,

You are dangerously close to 1st January 1900 (the earliest date Excel will process with its date functions) but handling leap years is tricky if you're trying to just manipulate as text, so please confirm no dates are before 1900. Fortunately the day and month have leading zeros so that simplifies the challenge.

You don't say if the sample dates are in different columns so my row 2 and 3 formulae just handle that format. The row 4 and 5 formulae use the length to check which date format is contained in column B.

How_Do_I.xlsx
ABCD
1DateStart DateEnd Date
21st Format1916/01-1917/1101-Jan-191630-Nov-1917
32nd Format1915/12/24-1916/07/2224-Dec-191522-Jul-1916
4Mix1901/11-1901/1201-Nov-190131-Dec-1901
5Mix1901/01/01-1902/01/0101-Jan-190101-Jan-1902
Sheet1
Cell Formulas
RangeFormula
C2C2=TEXT(DATE(MID(B2,1,4),MID(B2,6,2),1),"dd-mmm-yyyy")
D2D2=TEXT(EOMONTH(DATE(MID(B2,9,4),MID(B2,14,2),1),0),"dd-mmm-yyyy")
C3C3=TEXT(DATE(MID(B3,1,4),MID(B3,6,2),MID(B3,9,2)),"dd-mmm-yyyy")
D3D3=TEXT(DATE(MID(B3,12,4),MID(B3,17,2),MID(B3,20,2)),"dd-mmm-yyyy")
C4:C5C4=IF(LEN(B4)<16,TEXT(DATE(MID(B4,1,4),MID(B4,6,2),1),"dd-mmm-yyyy"),TEXT(DATE(MID(B4,1,4),MID(B4,6,2),MID(B4,9,2)),"dd-mmm-yyyy"))
D4:D5D4=IF(LEN(B4)<16,TEXT(EOMONTH(DATE(MID(B4,9,4),MID(B4,14,2),1),0),"dd-mmm-yyyy"),TEXT(DATE(MID(B4,12,4),MID(B4,17,2),MID(B4,20,2)),"dd-mmm-yyyy"))
 
Upvote 0

Forum statistics

Threads
1,215,026
Messages
6,122,743
Members
449,094
Latest member
dsharae57

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