Question on Date-Time format (SOLVED)

Barry Katcher

Well-known Member
Joined
Feb 25, 2002
Messages
4,053
Hello, group.

If this line of code:

Code:
    ActiveCell.FormulaR1C1 = (Date)

returns this: 6/30/2003

and this line of code:

Code:
    ActiveCell.FormulaR1C1 = (Time)

returns this: 8:24:15 PM

then why doesn't this:

Code:
    ActiveCell.FormulaR1C1 = (Date)
    Selection.NumberFormat = "m/d/yyyy h:mm:ss AM/PM"

return this: 6/30/2003 8:24:15 PM?

What it does return is 6/30/2003 12:00 AM.

Anyone have an idea what format I should be using to get the actual time and not have it default to 12:00? Thanx in advanx.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Re: Question on Date-Time format

Date returns only the Date stamp with no time information. Try using this...

Code:
ActiveCell = Now
Selection.NumberFormat = "m/d/yyyy h:mm:ss AM/PM"
 
Upvote 0
Re: Question on Date-Time format

ActiveCell.FormulaR1C1 = (Now)


...cos date onl returns the integer portion (ie the date), not the decimal portion (ie the time) of now, the combined date & time
 
Upvote 0
Re: Question on Date-Time format

Thanks, Tommy, it worked. I always thought NOW and TODAY returned volatile times, but this is static. Thanks again.
 
Upvote 0
Re: Question on Date-Time format

Now and Time as formulas are volatile and will be recalculated each time with the spreadsheet. However, this code is simply hard coding the current system time into the activecell.
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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