Darkness Soul Posted April 24, 2006 Share Posted April 24, 2006 Hi guys,I like to ask about a date select.. how my topic name tell, I want to select the daily births..The user open the page and, in a div, have all the members who are at birthday..But, my logic problem is: The table record the born, like... 20/10/1987, 09/06/1981.. and my select test if born is between afternoon and tomorrow.. this test is because i want to select between 3 days ago and 3 days after.. Actualy:[code]$sql = "SELECT id, born, name FROM tbMembers WHERE (born > $daysago AND born < $daysafter) ORDER BY born DESC";$query = mysql_query ( $sql , $conn );[/code]It will test the born year with 2006, so, never select...Thanks anyway.. =)D.Soul Quote Link to comment Share on other sites More sharing options...
fenway Posted April 25, 2006 Share Posted April 25, 2006 Sounds like this 'born' field isn't a DATE, but a CHAR field... this is the first issue. Also, you can use BETWEEN and some date math for N days before/after. Please clarify. Quote Link to comment Share on other sites More sharing options...
Darkness Soul Posted April 26, 2006 Author Share Posted April 26, 2006 Yo,Born is a TIMESTAMP field, like 20060426152712 (YmdHmi).My function return an array with three dates.. array( before , now , after );What I do? I call that function and as parameter, before is how many days ago, after is how many days after..What I want from the select? Check a date, like NOW().. into select, want to test a time begins $before and going to $after.. so, show me all results between these two fields..^^" sorry for "complex" english.. trying hard to learn faster \o\~~..Thanks, D.Soul Quote Link to comment Share on other sites More sharing options...
fenway Posted April 27, 2006 Share Posted April 27, 2006 I'm sorry, I really don't understand what you're getting at. Quote Link to comment Share on other sites More sharing options...
Darkness Soul Posted April 27, 2006 Author Share Posted April 27, 2006 Let me try one more time, if you don't understood, I will ask for help to 'rewrite' my question.. ;)You open my site... in the index, you have a list with who are at birthday.. to make that list, my script do:1. call the date function, that will calc the 'begin' and the 'end' of the date select;2. call the select, that will filter this date and order by date..3. print the listmy function is like:fuction calc_date ( $today , $days_before , $days_after , $date_format )so, i call it:[b]$array_date = calc_date ( date ('d/m') , 14 , 7 , 'd/m' ) ;[/b]My array:[b]array_date: 0 -> 13/4 1 -> 27/4 2 -> 4/5[/b]0 is $today - $days_before,1 is $today,2 is $today + $days_after.My SELECT is suppose to get all data between $array_date[0] and $array_date[2].. if the date match.. it will be listed.. so, in the site main, that will list all the guys in birth.. like:[b]SELECT id, born, name FROM tbMembers WHERE born >= $array_date[0] AND born <= $array_date[2] ORDER BY born DESC[/b]better now? ^^" sorry for the mess..D.Soul Quote Link to comment Share on other sites More sharing options...
fenway Posted April 27, 2006 Share Posted April 27, 2006 You could also do the following and not both the either the array or the PHP date functions at all:[code]SELECT id, born, name FROM tbMembers WHERE born BETWEEN >= NOW() - INTERVAL $days_before DAY AND NOW() + INTERVAL $days_after DAY ORDER BY born DESC[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.