The DateDiff() function can be used to find the time interval between two different dates. If you use the DateDiff function and the NOW function, you can find out how much time has passed since a certain date.
daysInteger = DateDiff(“d”, 2014/09/21″, NOW)
msgbox(“Fall started” & daysInteger & “days ago”)
The function works like this: DateDiff(“format”, Date1, Date2)
You must give the DateDiff function two different dates to calculate the difference between, and you must tell the DateDiff function what FORMAT you want it to calculate and display the difference in:
- For seconds use “s“
- For hours use “h“
- For days use “d“
- For months use “m“
- For years use “yyyy“
DIM birthday, daysInteger
birthday = inputbox(“Please enter your birthday in the format: January 1, 2014”)
daysInteger = DateDiff(“d”, birthday, NOW)
msgbox “You are ” & daysInteger & “days old.”
After working through the above example…
Use Notepad++ or some such program and create a script that:
- Declares variables to hold the user’s birthday and their age in years.
- Get the user’s birthday, using an input box.
- Calculate the user’s age in years, using the DateDiff function (**use the format for years).
- Display the user’s age in years using a message box along with a message like “You turn -years old- this year.”
OR take on this **Challenge**
Have a script that determines the users age in days and then have the user enter a certain number of days into an input box and then display the date on which the user will turn that many days old.
Save your script file and run it to test it. Then hand in your code as a .txt file.