Jump to content

date compare syntax


ionnnnutz

Recommended Posts

<?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?

Link to comment
Share on other sites

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.)
Link to comment
Share on other sites

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>";
}

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.