Add time to a date field in Ms access

Sivasan
Sivasan used Ask the Experts™
on
Hi there,
I have an event in access form where I have a datetime field where I take the date part of the field and I need to add a hard coded time of 8:30 am. Please let me know the correct format/Syntex for this.

Dim uptime as date

uptime = Format (entertime,"mm/dd/yyyy")       + 08:30  (when I try adding 8:30 doesn't work

so if entertime is 5/27/2012 10:00 am  
I want uptime to be 5/27/2012  8:30 am  so basically take the date value from entertime and add 8:30 am to it and assign it to uptime.

thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
try
uptime = Format (entertime,"mm/dd/yyyy hh:mm:ss")
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
NewTime = DateValue(upTime) +timeserial(8,30,0)
uptime = datepart(entertime)   +  #08:30:00#

However it's not clear where entertime is coming from and the syntax may need adjusting depending on the source.
11/26 Forrester Webinar: Savings for Enterprise

How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.

Author

Commented:
Worked.That was quick, thanks a billion...
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
sivasan,

I think you picked the wrong answer.  using the format() function will not change the value of a variable.  You will either need to use syntax similar to what I provided, or Peter provided to get rid of the 10:00 AM and replace it with 8:30

Commented:
lol, I think he wants to add time to the format, not add time to the date, not clear.
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Actually, I thought it was pretty clear:

"so if entertime is 5/27/2012 10:00 am  
I want uptime to be 5/27/2012  8:30 am  so basically take the date value from entertime and add 8:30 am to it and assign it to uptime."

uptime = DateValue(entertime) + timeserial(8,30,0)

Author

Commented:
Hi Fyed,

I just did
uptime = Format (entertime,"mm/dd/yyyy 08:30:00")  and it worked, I just saw the other two anwer right now, so I'm not sure.
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
interesting, but that will give you a string as your result, not a date/time value.

If that works for you, I'm ok with it.  Just wanted you to understand that using the format function returns a string, not a date/time value.

Dale

Author

Commented:
Hi Dale,
Thank you for your valuable comments, I will check on that.Sorry I missed seeing the post you two posted before I accepted the solution. I really really appreciate the time you all have taken to posted a solution.
Thank you very very very much!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial