Append Time Value to a Date Data Type Varaible

michaeljryan78

Registered User.
Local time
Today, 17:57
Joined
Feb 2, 2011
Messages
165
I have a variable (dtDueDate as Date) showing as 6/28/2013. I want to append a time value to it (dtMaxTime as Date) which is 5:00 PM so dtDueDate reads 6/28/2013 05:00:00 PM. I have been going in circles trying to figure this out. My goal is to append this date to a table field which has a datetime (General Date).
 
Thank you for the article, however I don't think that it covered what I need, or I may be a bit dense :) If I have a date (dtDueDate) as mm\dd\yyyy and I want to add to the end of the date a time (dtMaxTime) as hh:mm:ss AM\PM so that I finally come out with mm\dd\yyyy hh:mm:ss AM\PM, how would I accomplish this?
 
Code:
Sub TryThis
   dim d1 as date
   dim t1 as date
   dim d2 as date

   d1 = #12/31/13#
   t1 = #17:00#

   d2 = d1 + t1

   debug.print d2

End Sub
Does that help?
 
Access is smart so if it looks like a date with time Access will allow you to concatenate the two fields. I added CDate just to ensure it is stored as a Data Type Date.

Code:
Cdate(#6/27/2013# & " " & #5:00 PM#)

This will result in 6/27/2013 5:00:00 PM.
 
But dates are stored as numbers, so if you do this . . .
Code:
#6/27/2013# & " " & #5:00 PM#
. . . VBA will create a string, and then CDate() will convert it back to a number.

But I'm a pragmatist too. Whatever works. :)
 
That is why I like this forum, all different options are explored. Thank you! dtDueDate = CDate(dtDueDate & " " & dtMaxTime) worked great!!
 

Users who are viewing this thread

Back
Top Bottom