422,754 Members | 2,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,754 IT Pros & Developers. It's quick & easy.

DateAdd

100+
P: 243
I have a field where I enter an appointment date. In the after update event of that field I have the following code:

Expand|Select|Wrap|Line Numbers
  1. Me.Due_Date = DateAdd("d", 45, Me!Appointment_Date.Value)
This is working fine, adding 45 days to the current date. My question is, is there a way to add a specific time to the "due_date" field as well. In other words, instead of just adding the date 45 days forward can I also add a specific time?

Thanks for the help!
Nov 7 '17 #1
Share this Question
Share on Google+
4 Replies


PhilOfWalton
Expert 100+
P: 1,116
Use the same technique again.

Hours
Expand|Select|Wrap|Line Numbers
  1. Me!Due_Date = DateAdd("h", 12, Me!Due_Date)
  2.  
Minutes
Expand|Select|Wrap|Line Numbers
  1. Me!Due_Date = DateAdd("n", 30, Me!Due_Date)
  2.  
That should add 45 days, 13 hours & 30 minutes to your original date.

Incidentally, you don't need the word "Value"

Phil
Nov 7 '17 #2

100+
P: 243
Thank you for the response... but I have a question. When you say that will add 13 hours and 30 minutes to my original date, does original date mean the time the after update event triggers, because then it wont always be the same time, right?
Nov 8 '17 #3

PhilOfWalton
Expert 100+
P: 1,116
Although your Appointment Data appears as just a date, it is actually a date time combination, So Adding a time to the original date (After Update), (irrelevant that you have already added 45 days), will add the hours and the minutes to the updated appointment date.

If you want to see the date fully, use the "General Date" Format.

Phil
Nov 9 '17 #4

NeoPa
Expert Mod 15k+
P: 30,741
The point here is that a date value on its own is equivalent to midnight at the start of that date. IE. Friday 10 November == Midnight at the start of Friday 10 November.

Thus if you add 5 hours to the 'date' you get 05:00 on that same date. Does that clarify your thinking somewhat?

That's what Phil meant by a date value also being a date and time value. It's a date and time where the time part is midnight. On a 24 hour clock that's shown as 00:00 - which is exactly the value we have for time after midnight - Zero.
Nov 10 '17 #5

Post your reply

Sign in to post your reply or Sign up for a free account.