Converting YYYYMMDD into proper Date

dotsent

Board Regular
Joined
Feb 28, 2016
Messages
80
Office Version
  1. 365
Platform
  1. Windows
Hi!

I have an Excel 2016 worksheet with a data connection to db where I query contents to Excel. It is a simple table with invoice numbers and due dates. Those are exclusively unpaid overdue invoices. SQL query identifies if the invoice is open (unpaid). The date is kept as a decimal in the database and has a format YYYYMMDD

A1 cell in my workbook is equipped with a formula =TEXT(TODAY(); "yyyymmdd") - it displays the current date in the same format. The query uses value in this cell to identify if the open invoice is overdue (i.e. Due date is smaller than A1 value). This is done via table parameters setup. This works like a charm - I only get invoices in my table that are open + are past the due date.

I'm struggling to calculate the correct number of days overdue though. I have created an extra column to the table with formula "=A$1 - Due Date", however the format does not support correct calculations. E.g. on November 1st for an invoice with due date on October 1st the calculating process would work =20181101 - 20181001 = 100 days, which obviously isn't correct.

SQL query would not allow me to use CAST function to turn decimal value to DATE and I can't really mess around with the date format in cell A1 to keep it functional for query purposes.

I guess I'm looking for options how to turn value YYYYMMDD into properly formatted date in a helper column, which would be usable in formulas? How could I do that or are there alternative approaches?

Thanks!
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,938
Office Version
  1. 365
Platform
  1. Windows
Re: Coverting YYYYMMDD into proper Date

How about
=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))
 

Phuoc

Active Member
Joined
Apr 29, 2016
Messages
458
Office Version
  1. 2016
Re: Coverting YYYYMMDD into proper Date

One way:

=--TEXT(A1,"0000\/00\/00")
 

Phuoc

Active Member
Joined
Apr 29, 2016
Messages
458
Office Version
  1. 2016

ADVERTISEMENT

Re: Coverting YYYYMMDD into proper Date

You can save a couple of characters and do it this way...

=--TEXT(A1,"0000-00-00")
Yes, it's simpler.
 

dotsent

Board Regular
Joined
Feb 28, 2016
Messages
80
Office Version
  1. 365
Platform
  1. Windows
Re: Coverting YYYYMMDD into proper Date

Thanks guys! I used the =--TEXT(A1,"0000-00-00") option and it worked nicely! Option by Fluff worked too, however I found TEXT function to be simpler. I had to remove the "--" from ahead of TEXT though. What was the function of that?
 
Last edited:

Phuoc

Active Member
Joined
Apr 29, 2016
Messages
458
Office Version
  1. 2016
Re: Coverting YYYYMMDD into proper Date

What was the function of that?
Convert text to number,same above:

=VALUE(TEXT(A1,"0000-00-00"))

or:

=DATEVALUE(TEXT(A1,"0000-00-00"))
 

Forum statistics

Threads
1,148,157
Messages
5,745,107
Members
423,924
Latest member
Gazzat

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
Top