Sivasan
asked on
Add time to a date field in Ms access
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
However it's not clear where entertime is coming from and the syntax may need adjusting depending on the source.
ASKER
Worked.That was quick, thanks a billion...
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
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
lol, I think he wants to add time to the format, not add time to the date, not clear.
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)
"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)
ASKER
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.
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.
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
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
ASKER
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!
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!