Another date solution

Formula to the rescue

Getting dates into order is usually a job for Power Query, but not everyone has it or uses it so I still get requests for formulas to fix text dates.

The latest requested format is shown below.

The request was to create a single formula that would convert the text date/time in an Excel date/time.

The tricky bit here is the fact that the date and the hour can both be one or two digits – so the length of the string varies.

I broke the requirement into two parts and then combined the parts to end up with a very long final solution formula.

A date-time fact that you need to know in Excel. A date is a whole number and time is a decimal (fraction). A date has an underlying number 1 equals 1/1/1900 and every day since has its own sequential number. 43101 is 1 January 2018. Noon on that day is 43101.5 and 6AM on that day is 43101.25 and 6PM is 43101.75.

A file with the all the formulas is at the bottom of the post.

Extract the date

First we will extract the date. The formula in cell B2 is


The DATE function builds the date using Year number, Month number and the Day number, in that order.

The DATE function is very accommodating as it automatically converts text numbers into real numbers and it ignores leading and trailing spaces.


The year either starts in character position 7 or 8. The following MID function extracts the year.


Given that the year is preceded and followed by a space we can start the date in position 7 and extract 5 characters.

The MID function extracts form the middle of a text string. You provide the cell to extract from, the starting character position and then the number of characters to extract. The starting character position is included in the extracted text.

The above MID function will either include the preceding space or the trailing space as well as the year.

The DATE function is helpful and ignores the space (leading or trailing) and treats the text number as a year number.


My most popular blog post is on converting a text month name into a month number – we can use that technique here.


If you type 1Sep into a cell Excel with convert it into a date. This is what I am creating with


1 is combine with the first 3 letters of the text date to create 1Sep.

The MONTH function returns the number for September.


The day number is either one or two digits long. If we assume two digits then luckily the DATE function will ignore the space.


That’s how we extract the date from the text date.


This is the more complicated formula as it has to handle different positions for the time part of the string.

The TIMEVALUE function converts a text time into a a fraction – which is how time is stored in Excel. Dates are whole number and time is a fraction. 0.25 is 6AM, 0.5 is noon and 0.75 is 6PM.

The formula for cell C2 is

=TIMEVALUE(MID(A2,SEARCH(":",A2)-2,5)&" "&RIGHT(A2,2))

First issue – the text required for the TIMEVALUE function has a space between the time and the AM/PM. Our time doesn’t have a space.

& ” “&RIGHT(A2,2))

This part of the formula handles the space before the AM/PM.

The next problem we face is we don’t know where the time starts because the day could have one or two digits.


Whilst we don’t know where the time starts we can figure out where the colon is using the SEARCH function. Once we have the position of the colon we can deduct 2 from it to get the start of the time, assuming a two digit hour. If it is a one digit hour we get a leading space, but the TIMEVALUE function seems to handle that extra space ok. The length of a two digit hour time is 5 characters including the colon.

Date and time

To get the data AND the time you just add them together

The formula for cell D2 is

=DATE(MID(A2,7,5),MONTH(1&LEFT(A2,3)),TRIM(MID(A2,5,2)))+TIMEVALUE(MID(A2,SEARCH(":",A2)-2,5)&" "&RIGHT(A2,2))

Its quite long, but it does the job.

Thanks to Mike for asking the question.

Example Excel File







Creating a table of all combinations in Excel [Video]

Power Query solution

Let’s assume you have three state codes and four department codes and you want to create a table of all the possible 12 combinations (3 x 4). How do you do it so that it is flexible? i.e. if you add a new state or department it must be easy to update the combination table.

Get & Transformation

Power Query morphed into Get & Transform and now in the latest Excel 2016 subscription release Get & Transform has expanded on the Data Ribbon.

Filtering blanks made easy

In Excel the “Blanks” option is usually at the bottom of the list. This slows down selecting it.

If you have a lot of entries you need to scroll all the way down to bottom of the list to choose it – see image below.

But the word “Blanks” is searchable, so if you type b in the Search box – your work is done – no scrolling required – see image below.

If your column contains text you might need to type in bla.

Copying a Date Down a Long List in Excel

Two techniques make it quick and easy

There are a number of mouse and keyboard shortcuts for copying. But there is one type of copy that can be frustrating. Copying dates can be challenging because, in general, Excel wants to increment them, not copy them. There is a simple technique to instruct Excel to copy a date.

Columns in a Text Box

You learn something new every day.

Today I discovered that you can have columns within a text box.

If you right click the text box and choose Format Shape the Task Pane below should open on the right.

Click the third icon (Size and Properties) at the top and then open up the Text Box options.


The Columns button allows you to specify how many columns plus the gap between them.

Have fun.

Handling DR and CR at the end of numbers in Excel

Sorting out debits and credits

Some systems add DR and CR to the end of numbers when they export into Excel. This renders the values useless for normal calculations. You can use data cleansing techniques to remove the characters using formulas or Power Query. There is one function however that can perform calculations on these types of entries.