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
https://forums.phpfreaks.com/topic/47766-date-compare-syntax/
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
https://forums.phpfreaks.com/topic/47766-date-compare-syntax/#findComment-233340
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
https://forums.phpfreaks.com/topic/47766-date-compare-syntax/#findComment-233393
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
https://forums.phpfreaks.com/topic/47766-date-compare-syntax/#findComment-233954
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.