A VBA function to give serial date for date and time?

A

Android

Is there a VBA function which would convert a date into a serial number,
without you having to feed it the Year, Month, Day and time data as
individual values?

Had no luck finding it. Would make date & comparison so much easier.
 
M

Myrna Larson

Assuming you mean your date is text (a string), use the CDate or DateValue
function.

DateValue won't include the time component, CDate will.
 
K

keepITcool

dim dt as date
dt=dateserial(2004,4,3) (y,m,d)
dt=datevalue("3 sep 2004")

'note the string will evaluate using a 'locale' so might not work for all
users... e.g. datevalue("3 okt 2004") would work for me in Holland :)


keepITcool

< email : keepitcool chello nl (with @ and .) >
< homepage: http://members.chello.nl/keepitcool >
 
A

Android

The date is a "Date" , and not a string. I was aware of DateValue, but as
you say, that requires a string to be fed to it.


Myrna Larson said:
Assuming you mean your date is text (a string), use the CDate or DateValue
function.

DateValue won't include the time component, CDate will.
 
R

Ron Rosenfeld

The date is a "Date" , and not a string. I was aware of DateValue, but as
you say, that requires a string to be fed to it.

If the date is a true date, then it "is" a serial number.

So to express it you could use something like CDbl(dt)


For example, with a Date in Selection, this SUB will express the serial number:

Sub dtser()
MsgBox (CDbl(Selection.Value))
End Sub


--ron
 
Top