ionnnnutz Posted April 19, 2007 Share Posted April 19, 2007 <?php $actDate=date("d.m.Y"); echo $actDate; $activitate_zilnica2=("SELECT comp_notesid,date_format(comp_note_entry_date, '%d.%m.%Y') AS entry_date,comp_note_message FROM comp_pnote WHERE entry_date = '".$actDate."'"); $activitate_zilnica=mysql_query($activitate_zilnica2); while($activitate_zi=mysql_fetch_array($activitate_zilnica)) { echo "<div><span>", $activitate_zi['entry_date'], "</span><br><span>", $activitate_zi['comp_note_message'], "</span></div><br>"; } ?> $activitate_zilnica2=("SELECT comp_notesid,date_format(comp_note_entry_date, '%d.%m.%Y') AS entry_date,comp_note_message FROM comp_pnote WHERE entry_date = '".$actDate."'"); i wonder if that is the right syntax to compare 2 dates! Could somebody help me? Quote Link to comment Share on other sites More sharing options...
veridicus Posted April 19, 2007 Share Posted April 19, 2007 Typically you store your dates as unix timestamps. Then get all of the records for one day by using a range of seconds (midnight one day to midnight the next). This is relatively convenient and also the most efficient query. Quote Link to comment Share on other sites More sharing options...
c4onastick Posted April 19, 2007 Share Posted April 19, 2007 Typically you store your dates as unix timestamps. Then get all of the records for one day by using a range of seconds (midnight one day to midnight the next). This is relatively convenient and also the most efficient query. Ditto. That way you don't have to deal with the different date formatting issues. (1/1/07 vs 01/01/07 vs 01/01/2007 vs 01-01/07 vs 07-1-1 , etc.) Quote Link to comment Share on other sites More sharing options...
ionnnnutz Posted April 19, 2007 Author Share Posted April 19, 2007 but how should look the mysql query? Quote Link to comment Share on other sites More sharing options...
veridicus Posted April 19, 2007 Share Posted April 19, 2007 Looks like you just want everything after midnight today (based on your code), so assuming comp_note_entry_date is a unix timestamp, you'll want something like... <?php $actDate=date("d.m.Y"); echo $actDate; $beginning_of_day = time() - (time() % 86400); $activitate_zilnica2=("SELECT comp_notesid,date_format(comp_note_entry_date, '%d.%m.%Y') AS entry_date,comp_note_message FROM comp_pnote WHERE comp_note_entry_date >= ".$beginning_of_day); $activitate_zilnica=mysql_query($activitate_zilnica2); while($activitate_zi=mysql_fetch_array($activitate_zilnica)) { echo "<div><span>", $activitate_zi['entry_date'], "</span><br><span>", $activitate_zi['comp_note_message'], "</span></div><br>"; } ?> Quote Link to comment Share on other sites More sharing options...
bubblegum.anarchy Posted April 20, 2007 Share Posted April 20, 2007 mysql stores dates as YYYY-MM-DD Quote Link to comment Share on other sites More sharing options...
fenway Posted April 20, 2007 Share Posted April 20, 2007 Typically you store your dates as unix timestamps. Then get all of the records for one day by using a range of seconds (midnight one day to midnight the next). This is relatively convenient and also the most efficient query. Actually, you should store your dates and DATE/DATETIME columns -- let mysql deal with storage. 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.