Share via


Working with Dates and Times

Microsoft® Visual Basic® for Applications (VBA) provides a data type for storing date and time values, the Date data type. Convenient as the Date data type is, manipulating date values in VBA can still be tricky. To easily work with dates, you must understand how VBA stores date values internally.

In This Section

  • The Date Data Type
    Store date and time values by using the Date data type.
  • Getting the Current Date and Time
    Three functions in Microsoft® Visual Basic® for Applications (VBA) can tell you exactly when it is: the Now, Date, and Time functions.
  • Formatting a Date
    Use predefined formats to format a date, or create a custom format for a date.
  • Date Delimiters
    Understand how to indicate to Microsoft® Visual Basic® for Applications (VBA) that a value is a date.
  • Assembling a Date
    Break down dates into component parts — day, month, and year — to perform a calculation on one element, and then reassemble the date.
  • Getting Part of a Date
    Get information about a date, such as what quarter or week it falls in or what day of the week it is.
  • Adding and Subtracting Dates
    Learn how to add and subtract intervals to given dates.
  • Calculating Elapsed Time
    Use functions to calculate the time that has elapsed between two dates, and present that time in the desired format.
  • Getting the Most Out of Visual Basic for Applications
    Write code that is fast, efficient, easy to read and maintain, and, if possible, reusable with a solid working knowledge of Microsoft® Visual Basic® for Applications (VBA) — what features the language includes and what you can do with it.
  • Working with Strings
    Understand how to get information from strings.
  • Working with Numbers
    Learn how to use numeric values and data types in Microsoft® Visual Basic® for Applications (VBA).
  • Working with Files
    Understand the Microsoft Scripting Runtime object library, and work with drives, folders, and files as objects.
  • Understanding Arrays
    Use arrays when you must store a number of values of the same type, but you do not want to create individual variables to store them all.
  • Tips for Defining Procedures in VBA
    Define a Function or Sub procedure, and use the options available to you to make your code more extensible or more flexible.
  • Optimizing VBA Code
    Understand how to streamline your Microsoft® Visual Basic® for Applications (VBA) code to streamline your memory requirements.