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. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 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

  4. #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

  5. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 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.

  6. #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
  •