Wrapping Date/Time in Cell

Jeffrey Mahoney

Well-known Member
Joined
May 31, 2015
Messages
2,787
Office Version
  1. 365
Platform
  1. Windows
I want to display the date on the first line and the time on the second line in a cell.

Since Excel won't wrap a number in a cell and Date/Time values are numbers, all you get is ### in a column when the number is too long for the column width.

Is there any way to add a hard return in the number formatting string?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Wrap text
Alt Enter between date and time
change width of column
01/04/2020 23:25:00
 
Upvote 0
Change cell to wrap text. Custom number format enter dd/mm/yyyy then press CTRL-J then hh:mm works for me
 
Upvote 0
@sandy: Thank you, I know about Alt-Enter. I have a ton of new data coming into this database I don't want to have to create a routine to edit the cells

@steve the fish: Nice! Didn't know about Ctrl-J. It kinda hides the time after pressing Ctrl-J, but not a problem to deal with it.

Thank you both.
 
Upvote 0
Oh, bad news. Excel doesn't know that the time wrapped below and still puts ### when the column is too narrow. There's plenty of space, but it refuses.
 
Upvote 0
Oh, and just for your reference Sandy, If you add the hard return, the date/time is turned into a string. No more calculations can be performed
 
Upvote 0
Work-around suggestion
- Add another column as shown, with wrap text.
- Hide column B
- Do your calculations still referencing the hidden column B

20 04 02.xlsm
BC
1Date TimeDate Time
22/04/2020 11:392/04/2020 11:39
Date Time
Cell Formulas
RangeFormula
C2C2=TEXT(B2,"d/mm/yyy"&CHAR(10)&"hh:mm")
 
Upvote 0
Thanks Peter. I have some code to import daily reports. I could incorporate a new column into that. The problem is that autofilter doesn't see that as a date; sorting becomes wonky, because if I don't have the format in yyyy/mm/dd it sorts January 2020 before December 2019. Each date becomes a stand-alone string not related to month or year in the autofilter.

Sorry everyone. It seems I'm just here punching holes into your ideas. I could divide the columns into Date and Time, but I don't think I'll reduce any precious column width.
 
Upvote 0
The problem is that autofilter doesn't see that as a date; sorting becomes wonky
Keep the real date/time column visible as well, but very narrow if you want then you can still use its AutoFilter. You could even format text in this column same as background if you don't want the look of the ###

or

Add yet another column that ranks the original Date/Time values and use that to sort. The original column could then be hidden or even deleted since you are using code and could make both of the new columns actual values instead of formulas.

Cell Formulas
RangeFormula
C2:C10C2=TEXT(B2,"d/mm/yyy"&CHAR(10)&"hh:mm")
D2:D10D2=RANK(B2,B$2:B$10,1)
 
Upvote 0
Oh, bad news. Excel doesn't know that the time wrapped below and still puts ### when the column is too narrow. There's plenty of space, but it refuses.
Not sure if you are still looking for this, but an extra step needs to be taken to make the date time wrap correctly.

In my example I used
mm/dd/yy Ctrl-J
hh:mm AM/PM

After you add the format follow these steps.

1. On the alignment tab uncheck "Wrap Text" if it is already selected
2. Select "Shrink to fit"
3. Reselect "Wrap Text"

"Shrink to fit" will be greyed out when you select "Wrap text", but it is consistently resolving the wrap issue I am having.

1674839578186.png


1674839624492.png
 
Upvote 1

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

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