Date Formatting (don't put slashes, but get with slashes)

Sahak

Well-known Member
Joined
Nov 10, 2006
Messages
1,008
Office Version
  1. 2016
  2. 2013
  3. 2011
  4. 2010
  5. 2007
I all,
I would like to have the cell formatted MM/DD/YYYY.
Is it possible to format or to use VBA, if I in the cell will enter for example 040512 (no slashes), after finishing the entry, it will show 04/05/2012, if I enter 100421 (no slashes), after finishing the entry, it will show 10/04/2021.
Thank you in advance
 
Thank you Peter very much, good catch. it is good to know. It gives a problem with sorting too:unsure:
IF you want to sort, better transform the "040512" Text format to Datevalue format.
try this. (suppose "040512" is in A1 cell)
Excel Formula:
=DATE(RIGHT(A1,2)+2000,LEFT(A1,2),MID(A1,3,2))
and you can use formula "TEXT" to format "mm/dd/yyyy".
try this
Excel Formula:
=TEXT(B1,"mm/dd/yyyy")
of course, you can combine above two formula to get the result directly.
Excel Formula:
=TEXT(DATE(RIGHT(A1,2)+2000,LEFT(A1,2),MID(A1,3,2)),"mm/dd/yyyy")
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
try this. (suppose "040512" is in A1 cell)
Excel Formula:
=DATE(RIGHT(A1,2)+2000,LEFT(A1,2),MID(A1,3,2))
That would require column A to specifically be formatted as Text prior to any data entry. If the format is General then the leading zero will be dropped and that formula would return incorrect results.

of course, you can combine above two formula to get the result directly.
Excel Formula:
=TEXT(DATE(RIGHT(A1,2)+2000,LEFT(A1,2),MID(A1,3,2)),"mm/dd/yyyy")
But then any date sorting would not work as the text values would be sorted alphabetically.

@Sahak

I have removed the 'Mark as solution' from post #12 as clearly it is not the post containing the solution to your question. Once you have decided, mark the actual post that contains the solution. If no post contains a solution then don't mark any.

I would try this as a formula approach.
Column A can be formatted as General or Text (mine is General - hence the leading zero was dropped from my A1 entry)
Column B is formatted as the Date format mm/dd/yyyy
Any sorting based on column B should sort in correct date order.

Sahak.xlsm
AB
11252201/25/2022
211032111/03/2021
Sheet3
Cell Formulas
RangeFormula
B1:B2B1=DATE(20&RIGHT(A1,2),LEFT(TEXT(A1,"000000"),2),MID(TEXT(A1,"000000"),3,2))
 
Upvote 0
Solution
Sorry about marking in the wrong place, I will note that, so I'm putting it now on post #13, I think it will be correct:)
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

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