Custom Date Format with Time Format Optional

PapaSki

New Member
Joined
Aug 10, 2006
Messages
3
I'm a long-time lurker and first-time poster.

I have a data column called "Deadline." Sometimes, the deadline is only a date, a time or both. I would like to enter only the data required (date, time or both), and I would like to format the cell as follows:

date only
ENTER: 10/1/07
FORMAT SHOWS: Mon, 10/1/2007

time only
ENTER: 5 p
FORMAT SHOWS: 5:00 pm

both
ENTER: 10/1/07 5 p
FORMAT SHOWS: Mon, 10/1/2007 5:00 pm

Is there a way to set up a custom number format to do this? When I use "mmm, m/d/yyyy, h:mm am/pm" and enter the date only, it automatically adds midnight as the time.

I'd prefer to use custom number format, if possible, but I'll happily use a formula if necessary. I cannot use VBA because I have to share the spreadsheet and it's a nightmare in our company for various reasons.

Thanks in advance for any insight or help.

David
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
David

This is impossible without VBA as far as I can see, sorry.:eek:
 
Upvote 0
Hello David,

Not quite what you want but perhaps this would help.....

If you use the following custom format

[>1]mmm, m/d/yyyy;;h:mm AM/PM;

then if you enter a time it will only show the time, if you enter a date it will show the date....
 
Upvote 0
barry

I can't believe that works.:)

But then again I never realised you could just enter the time as 5 p.:)

I thought Excel would see that as text, hence the suggestion that code would be needed.
 
Upvote 0
Thanks for the quick replies, Norie and Barry.

Barry: I cut and pasted your suggestion:

[>1]mmm, m/d/yyyy;;h:mm AM/PM;

Entering the time alone works perfectly. For some reason, when I enter the date, it displays the three-letter abbreviation for the month instead of the day of the week. For instance, if I enter "10/1," it displays "Oct, 10/1/2007." I tried adding a fourth "m," a space before "mmm," but nothing seems to make it return "Mon, 10/1/2007."

It also won't display an entry that includes both date and time. If I look in the formula bar, it's reading it correctly ("10/1 5 p" becomes "10/1/2007 05:00:00 PM"), but drops off the time in display. Not a problem if that's the best Excel's custom number format will allow.

Finally, if you have time to educate me, would you explain the syntax? What does [>1] do? Also, what role do the double semi-colons and the ending semi-colon play?

And Norie, I found out about the "5 p" capability by pure accident one day years ago. It's a big help. Amazing what hours of obsession turn up!

Thanks a bunch.

David
 
Upvote 0
I'm still trying to work out how I got the above to work.....

If you want day of week change to this slightly amended version, using ddd instead of mmm

[>1]ddd, m/d/yyyy;[<=1]h:mm AM/PM

Basically because a day is 1 in excel any time is less than 1 and any date is greater than 1 so the above formats values greater than 1 as dates and those less than 1 as times....but I don't know a way of making it show dates and times automatically, sorry
 
Upvote 0
Barry:

Okay, I feel like a space cadet. Of course I'm supposed to use "d" not "m." Thanks for being so gracious about my momentary brain lapse.

Dates AND times would be nice, but you've already gotten me farther than a I thought possible. Thanks for the assist.

David
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

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