today vs. now

  • Thread starter Thread starter mike allen
  • Start date Start date
M

mike allen

i would like to use "today" in code, but i can't get it to work.
i can use "now" and it works, but i need the integer format that 'today'
provides.
i have tried rounding, declaring at integer, cint(now), etc.
sub temp()
cells(1,1)=today
end sub

thanks, mike allen (seems like my questions are getting simpler, not more
complex like they should be)
 
cells(1,1)=date

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
There's no "today" function in VBA. However you can use the equivalent
Date function:

Public Sub temp()
Cells(1, 1).Value = Date
End Sub
 
Hi Mike

how about

Cells(1,1), = Format(Now(), "mm/dd/yyyy")

Cheers
JulieD
 
it does not work because it is not a builtin function. Therefore, write
your own. mine is below:


Public Function Today() As Date
' Returns a date that does not contain the current time in it.
Today = Now() - Time()
End Function
 
Date is the VBA equivalent to the worksheet function Today.

You can strip the time from Now using Int

Int(now)

demo'd from the immediate window:

? date
1/11/2005
? int(now)
1/11/2005
? now
1/11/2005 11:18:24 AM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top