views:

62

answers:

3

So the function =Now()....is there a way I can use this and only get the date, not the time?

or is there just a function for this idea?

thanks Justin

+4  A: 

There is a Date function.

tlayton
so how do I use this?? i can use =Now() in VBA to get the current date and time, but it will not allow me to enter Date() or =Date(). it automatically takes away the () and the function does not seem to work the same way as =Now()
Justin
Date is the correct function to use. And yes, in the code editor, it will remove the ()
Albert D. Kallal
ah i see...i stand corrected. mistake else where was throwing me off. apologies...and thanks!
Justin
+1  A: 

You could also use Format$(Now(), "Short Date") or whatever date format you want. Be aware, this function will return the Date as a string, so using Date() is a better approach.

rob_g
what would i need to do to the above to get a date format of 28-Sep-10? Thanks I appreciate it!
Justin
Format$(Date(), "dd-MMM-yy"). There is also the Format function which returns a variant. If you know you're going to need a string to be returned, use the Format$ function.
rob_g
In code, you can generally use # to surround the date. Eg: #09/28/2010#However, the above can be messed up by date formatting, so another choice is dateserial() command. The syntax is dateserial(year,month,day), so DateSerial(2010,9,28)
Albert D. Kallal
wow thanks guys! i learned a lot with a simple question!! i love to do so because I am an aspiring student! thanks very much!
Justin
You can also restore the date datatype from a string representation of a date by passing it through the DateValue() function. But this question is completely wrongheaded in recommending using Format() just to get the date part.
David-W-Fenton
+2  A: 

Dates in VBA are just floating point numbers, where the integer part represents the date and the fraction part represents the time. So in addition to using the Date function as tlayton says (to get the current date) you can also just a date value to a integer to get the date-part from an arbitrary date: Int(myDateValue).

Dean Harding
cool! thanks for the help!
Justin
Why would anyone do that when there's a function specifically defined to return the integer part alone? That is, why make two function calls when one will do the job?
David-W-Fenton