1,105,177 Community Members

use unixtimestamp in mysql query.

Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

i want to compare dates stored in database in the format yyyy-mm-dd by changing it in unixtimestamp in the mysql query.for this my query is

$bquery="SELECT * FROM rt_booking WHERE rt_unit_id='".$_POST['unit_id']."' AND (SELECT UNIX_TIMESTAMP(str_to_date(rt_start_date,'%Y-%m-%d'))>=".$my11." OR SELECT UNIX_TIMESTAMP(str_to_date(rt_end_date,'%Y-%m-%d'))<=".$my22.")";

but it is giving syntax error.

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 219 [?]
Skill Endorsements: 21 [?]
Featured
 
2
 

Are you sure the second and third SELECT keywords have to be there. Would this be OK:

$bquery="SELECT * FROM rt_booking WHERE rt_unit_id='".$_POST['unit_id']."' 
AND (UNIX_TIMESTAMP(str_to_date(rt_start_date,'%Y-%m-%d'))>=".$my11." 
OR UNIX_TIMESTAMP(str_to_date(rt_end_date,'%Y-%m-%d'))<=".$my22.")";
Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

thank you broj1.it is working.

Question Answered as of 1 Year Ago by broj1
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article