Results 1 to 5 of 5
  1. #1
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA date/time type (Excel VBA )

    I know you can declare a variable as date, but is there a type to store date/time... like the NOW() function? Or must it stay variant!
    Regards,
    Rudi

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: VBA date/time type (Excel VBA )

    The Date data type is in fact a date/time data type, it can hold both a date and a time part. A Date variable is stored as a floating point number.
    The integer part is the number of days since December 30, 1899; for example, today (June 21, 2005) is stored as 38524.
    The fractional part is the time as a fraction of a whole day, i.e. midnight = 0, 6 AM = 0.25, 12 noon = 0.5 and 6 PM = 0.75.
    So June 21, 2005 6:00 PM is stored as 38524.75.

    You can use a Date variable like this:

    Dim dtmDate As Date
    dtmDate = Now

  3. #3
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA date/time type (Excel VBA )

    Aah...tx. So I can also assign a time value in Date. It will simply store it as 0.75...?

    Thankyou!
    Regards,
    Rudi

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: VBA date/time type (Excel VBA )

    Yes, you can assign a time value to a Date variable; as stated, it will be stored as a fraction. If you type Date in the Visual Basic Editor (in the Immediate window or in a module) and press F1, then select 'Date, data type', you'll get more info.

  5. #5
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA date/time type (Excel VBA )

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Regards,
    Rudi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •