The Microsoft Excel NOW Function returns the current date and time. When you need to keep track of when particular activities are accomplished or when you need to reference the current date and time in your spreadsheet, this feature comes in handy. The NOW Function is simple to use and may save you time by automatically changing the date and time every time you open or refresh your spreadsheet.
Syntax
NOW()
Arithmetic operations with a date.
Formula | Comment |
=NOW() + 28 | Add 28 days from the current date |
=NOW() – 28 | Subtract 28 days from the current date |
If the function does not return the current date and time. You can use the keyboard function keys to execute the excel function. Press Shift + F9 – to calculate the current worksheet.
Keyboard Shortcut
Ctrl + – to insert the current date in your excel sheet
Ctrl + Shift + – to insert the current time in your excel sheet
Use the Now function with Text function
The below formula returns only the current date as a string.
=TEXT(NOW(),"MM-DD-YYYY")
You can use the & operator to return the current date and time in your report along with some text.
="Today date is " & TEXT(NOW(), "MM/DD/YYYY")
How to compute VBA execution time using NOW ()
Assign the current date and time to a variable strTime, At the End of the script assign to a variable endTime. Subtract and message the execution time. In the below example, the message box returns the script execution time in seconds.
Sub generateRand()
strTime = Format(Now(), "SS")
For i = 1 To 100000
ActiveSheet.Cells(i, 1).Value = Math.Rnd()
Next
endTime = Format(Now(), "SS")
MsgBox "Total execution time : " & endTime - strTime
End Sub
Conclusion
It may be used to design formulae that update the date and time when the spreadsheet is opened or recalculated, as well as to check the execution of your VBA code. The NOW function may also be used to display dates and times in various formats and to calculate differences between two dates.
You can use the Excel TODAY function, which returns only the current date.
If you have any questions, please leave a comment below and I will get back to you as soon as possible.