Combining two fields for single datetime?

Last Post 24 Jan 2011 06:47 AM by rm. 5 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages Not Resolved
dstoltz
New Member
New Member

--
21 Jan 2011 07:31 AM
Hi All,

I have two fields in the database, eventdate (ie, 1/1/2011) and another field for eventtime in 4-digit military time (ie. 1830)

Is there any way in a query to combine these two fields?

I want to do:

SELECT x,y,z FROM TABLE WHERE convert(datetime,eventdate) >= '1/1/2010 06:30:00 PM'

 - where eventdate in the above query would need to be the combination of eventdate and eventtime fields.

Not only do the fields need to be combined, but also the time converted from 4-digit to the above 06:30:00 PM format. (Unless SQL can compare 4 digit time to normal format)...?

Any advice?

Thanks!
rm
New Member
New Member

--
21 Jan 2011 09:58 AM
Get partial:

SELECT x,y,z FROM TABLE WHERE convert(datetime, (eventdate + ' ' + stuff(eventtime, 3, 0, ':')))
dstoltz
New Member
New Member

--
21 Jan 2011 11:55 AM
Hate to sound so dumb, but you lost me with the "stuff" part....
rm
New Member
New Member

--
21 Jan 2011 12:08 PM
That converts '1830' to '18:30'.
dstoltz
New Member
New Member

--
24 Jan 2011 04:13 AM
That's awesome - thanks RM...

So can I make a time comparison with 18:30 format?

In other words, will it work if I do something like:
WHERE datetimestamp >= '1/1/11 18:30'

(assuming datetimestamp uses the same time format)

I'm going to try it - just want to make sure this is reliable....thanks again.
rm
New Member
New Member

--
24 Jan 2011 06:47 AM
Should work.


Acceptable Use Policy
---