Converting date field to txt

djbe17

Board Regular
Joined
Jun 18, 2007
Messages
51
Office Version
  1. 365
Platform
  1. Windows
Hi all ,
tricky formatting problem i'm trying to work through.
We use an external data set ( SFG20) which have used the format of 00-00 to record records.
When extracted to use in excel tables these are recognised as dates and converted - so a record with 06-04 is converted to 06-Apr ( with value of 45022 )

i have tried many options of formatting to DD-MM, and then copy as values but although this looks OK values with cells are still incorrect.

Added to this some SFG20 codes are fine as 44-04 is imported correctly - the image below i hope make this clearer, green cells are as expected, red are cells i need to correct.

Any thoughts on a formula or method to copy paste to correct this?

Many thanks all.
 

Attachments

  • Screenshot 2023-03-28 115037.jpg
    Screenshot 2023-03-28 115037.jpg
    27.2 KB · Views: 8
  • Screenshot 2023-03-28 115738.jpg
    Screenshot 2023-03-28 115738.jpg
    47.4 KB · Views: 8
Last edited:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
To convert a date like "29-Aug" to the text value "29-Aug", you can use the following formula (for an example value in cell A2):
Excel Formula:
=TEXT(A2,"dd-mmm")

If you wanted to overwrite the value, you could use VBA. The VBA equivalent of the TEXT function is FORMAT.
 
Upvote 0
Solution
Assuming the SFG20 data is in some other format like a text file like this:
Code:
06-04
30-03
23-19
29-08
44-04
44-04
44-04
44-04
44-04
44-04
44-04
23-02
23-02
16-05
20-12
63-06
63-06
Bringing the file in through Power Query would initially result in a table with that as text, however if any of the cells are modified, they'd turn into dates if possible. What would work is to add an apostrophe before the data, then it would always be text.
Power Query:
let
    Source = Table.FromColumns({Lines.FromBinary(File.Contents("C:\Temp\SFG20.txt"), null, null, 1252)}),
    AddedCustom = Table.AddColumn(Source, "Custom", each "'" & [Column1], type text)
in
    AddedCustom
That results in this table:
Book1
AB
1Column1Custom
206-0406-04
330-0330-03
423-1923-19
529-08'29-08
644-04'44-04
744-04'44-04
844-04'44-04
944-04'44-04
1044-04'44-04
1144-04'44-04
1244-04'44-04
1323-02'23-02
1423-02'23-02
1516-05'16-05
1620-12'20-12
1763-06'63-06
1863-06'63-06
Sheet2

NOTE: The haphazard justification in the display above is an XL2BB anomaly. In the actual table, ALL values are Left Justified since they are all considered Text, but as noted some of the values in Column A would convert to dates if edited.
What you don't see above is that once the data is "seen" by Excel as text, that leading apostrophe "disappears":
1680001942102.png

The down side is if Excel has reformatted the modified cell to hide the first apostrophe. On a Refresh, modified cells will end up with two apostrophes and will subsequently always display that way.
1680002250726.png

Clearing the cells doesn't fix it either, only deleting the column does. Of course, simply adding an apostrophe manually to the text file would work too!

Good news though, there's new options coming that might help. There are new Automatic Data Conversion options in the works:
1680002449087.png

I honestly don't know if that would help, but it's promising.
 
Upvote 1

Forum statistics

Threads
1,224,752
Messages
6,180,742
Members
452,996
Latest member
nelsonsix66

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