In Query: Add time and date together & getting error

oliviar

Board Regular
Joined
Sep 12, 2010
Messages
184
Hi Guys,
I have a date column and a time column with values in them. I want to add the two together to produce a date AND time column. I don't care if its formatted as a number.
When I try it the 'easy' (and clearly wrong) way, I get an error.

What I'm doing is:
Expr1: [date]+[time]

What SHOULD I be doing?

Thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Maybe:
Exp1: CDate([Date]) + CDate([Time])
Does that work? If not, what are the data types of the fields called here [Date] and [Time]?

Note: I would urge you not to name columns Date or Time as these are reserved words that refer to the VBA Date and VBA Time functions. They introduce difficult to trace errors at times when used as column names. Perhaps you chose these terms here only by way of example.

ξ
 
Upvote 0
Hi Xenou,
They are not called date and time, they are [etc etc etc etc date mmddyy] and [etc etc etc etc time hhmm]. I just called them that in here to make it easier to write.

They are both Date/Time fields, which is why I am so confused they won't just add together.
:eeek:
 
Upvote 0
I'm afraid to tell you that it works fine for me:

[MyDate] --> a datetime field with value 5/5/2011
[MyTime] --> a datetime field with value 5:11 PM

Query:
Select [MyDate] + [MyTime] As Exp1 FROM Table1;

Result:
5/5/2011 5:11 PM


Note that also fine is:
Select CDate([MyDate]) + CDate([MyTime]) As Exp1 FROM Table1;
As per my original post.
 
Last edited:
Upvote 0
HI Xenou,
Your Cdate solution works for me too. Thank you so much.
But still, trying to add them straight up only produces an error.

What IS that Cdate function doing that is so special?
:eeek:
 
Upvote 0
No idea really. :( CDate is simply a good "precaution" in case Access doesn't know the "dates" really are dates.
 
Upvote 0

Forum statistics

Threads
1,224,502
Messages
6,179,126
Members
452,890
Latest member
Nikhil Ramesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top