Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combine date and time fields

Status
Not open for further replies.

junkjones

Programmer
Jul 14, 2000
52
GB
Hi Everyone,

Is there a way to combine two fields in a query? I have a DATE field, and a TIME field. But in my SQL statement I want to say

select * from table
where DATE+TIME BETWEEN 'date+time' AND 'date+time'

can this be done? I know in other DB's you can just say TIMESTAMP(date, time) and it will combine them together, but I can't get that to work in MySQL.

Any help is very much appreciated!
 
Happily, since MySQL stores dates in YYYY-MM-DD format, date order and alphabetical order are one and the same.

How 'bout:

WHERE concat(datefield, ' ', timefield) BETWEEN '<onedatetimestamp>' and '<anotherdatetimestamp>' Want the best answers? Ask the best questions: TANSTAAFL!
 
This did the trick! Thanks for your very fast response :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top