Formatting dates

jerH

Board Regular
Joined
Dec 3, 2008
Messages
168
I use the following code to populate a date field on a sheet right now

Code:
ws.Range("E7").Value = Format(DateSerial(CInt(Left(raceDate, 4)), CInt(Mid(raceDate, 5, 2)), CInt(Right(raceDate, 2))), "Long Date")

raceDate is a string...so for example if its value was "20141101" the output I'd get would be Saturday, November 1, 2014

This is great, except on Wednesdays :)

On Wednesdays, the string becomes so long that it runs into some other elements on the sheet.

I can think of a couple of approaches
-- storing the string, splitting it on commas, select casing the first element and replacing Monday with Mon, Tuesday with Tues, Wednesday with Wed (the real offender), etc
-- counting characters and reducing the font size when the count gets too high

But I was wondering if the collective genius of this forum had a better answer?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
As it's just formatting you have the option within the format function to create your own format.
Just change your statement to:

Code:
ws.Range("E7").Value = Format(DateSerial(CInt(Left(raceDate, 4)), CInt(Mid(raceDate, 5, 2)), CInt(Right(raceDate, 2))), "DDD, MMMM, DD, YYYY")
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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