Combining two fields for single datetime?

Last Post 24 Jan 2011 05:47 AM by rm. 5 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
dstoltz
New Member
New Member

--
21 Jan 2011 06: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 08: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 10:55 AM
Hate to sound so dumb, but you lost me with the "stuff" part....
rm
New Member
New Member

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

--
24 Jan 2011 03: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 05:47 AM
Should work.
You are not authorized to post a reply.

Acceptable Use Policy