ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   A VBA function to give serial date for date and time? (https://www.excelbanter.com/excel-programming/303483-vba-function-give-serial-date-date-time.html)

Android[_2_]

A VBA function to give serial date for date and time?
 
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.



Myrna Larson[_3_]

A VBA function to give serial date for date and time?
 
Assuming you mean your date is text (a string), use the CDate or DateValue
function.

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

On Wed, 7 Jul 2004 17:08:56 -0400, "Android" wrote:

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.



keepITcool

A VBA function to give serial date for date and time?
 
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


"Android" wrote:

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.





Android[_2_]

A VBA function to give serial date for date and time?
 
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" wrote in message
...
Assuming you mean your date is text (a string), use the CDate or DateValue
function.

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

On Wed, 7 Jul 2004 17:08:56 -0400, "Android"

wrote:

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.





Ron Rosenfeld

A VBA function to give serial date for date and time?
 
On Thu, 8 Jul 2004 08:56:21 -0400, "Android" wrote:

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

Android[_2_]

A VBA function to give serial date for date and time?
 
Thank you. This really clarifies it for me.

Android.
"Ron Rosenfeld" wrote in message
...
On Thu, 8 Jul 2004 08:56:21 -0400, "Android"

wrote:

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




Ron Rosenfeld

A VBA function to give serial date for date and time?
 
On Thu, 8 Jul 2004 10:50:30 -0400, "Android" wrote:

Thank you. This really clarifies it for me.

Android.


You're welcome.


--ron


All times are GMT +1. The time now is 12:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com