Vba datetime function in Excel

The Date and Time function in VBA plays a key role in applications related to scheduling and Attendance Monitoring.

Any Excel sheet with data, will have a date column associated with it and a method to work with it is inevitable.

The Date and Time function in VBA offers a number of methods which are discussed as below.

Broadly, There are three things associated with this feature.They are




The 'Date' returns the Date portion of the current date.It can be converted to any format using the format function.

The 'Time' returns theTime part of the current date and time, which can also be formated accordingly.

The 'Now' returns the whole Date and Time.

These functions are very useful while programming a complex application in VBA.

For example, If we want a code to execute on a particular day or after a particular time,

then we can use this Date and Time function to handle these requirements.

Also, there are other features associated with these functions.

For instance, The Date can be used to return day,month and year part alone.

Also, the Time part can be used to retrive Hour, Minute or the Seconds part.

The following example illustrates this

  1. Sub date_time()
  2. MsgBox "Current Date : " & Date
  3. MsgBox "Current Time : " & Time
  4. MsgBox "Current Date and Time : " & DateTime.Now
  5. MsgBox "Current Day " & Day(Date)
  6. MsgBox "Current Month " & Month(Date)
  7. MsgBox "Current Year : " & Year(Date)
  8. MsgBox "Hour part : " & Hour(Time)
  9. MsgBox "Minute part : " & Minute(Time)
  10. End Sub
  11. excel vba datetime function


excel vba datetime function

excel vba datetime function

excel vba datetime function

excel vba datetime function

excel vba datetime function

excel vba datetime function

excel vba datetime function

excel vba datetime function


You can find similar Excel Questions and Answer hereunder

1) How to use logical operators in VBA

2) How can worksheet functions be accessed in VBA?

3) What is a module in VBA. How to create a module in VBA

4) How to convert a number or string into a data with the cdate function

5) What are the various functions of the worksheet in Excel VBA

6) What is a function in VBA. How to create a function and how to call a function

7) What is variable scope in VBA, how do variable can be reach from other function or routines in VBA

8) Various important math functions in VBA (trigonometry, algebra, exponential, �)

9) Here we show you advanced VBA array functions, like splitting arrays, Lbound, Ubound

10) How to create a subroutine in Excel VBA. Subroutines explained


Here the previous and next chapter