Reputation: 492
I have not found a solution to this online, because I think its the way i am using the date format.
Problem: I have a date format: 2013-06-07 This formate is created by the following:
$thedate = (string) substr($item->children('http://www.w3.org/2005/Atom')->updated,0,-15) . ' - ';
- Which is taken from a RSS feed, and trimmed so only the year, month and day is represented.
I then use this, to get the same, each is todays date:
$day = (string) date('Y-m-d');
So when I do a IF statement, the days should match, before it enters into the database:
if($day == $thedate) {
echo ($day . '\n' . $thedate);
$sql = "INSERT INTO rssFeed (date, stage, title, description, location, billtype, link) VALUES('".
$thedate ."','". $stage . "','" . $title . "', '" . $desc ."', '" . $location ."', '" . $billtype ."', '". $linkurl ."')";
//print_r($sql);
$inres = $mysqli->query($sql);
print_r($mysqli->error);
} else {
echo ('They do not match');
}'
It works fine without the IF statement, and I have printed both dates and they are identical, but, for whatever reason, the statement comes up as, not the same, and only 'They do not match' in console, or put into the database. No errors.
Any ideas ?
Upvotes: 0
Views: 52
Reputation: 1544
Try this:
$day = date("Y-m-d"); //get rid of the (string) cast
$thedate = date("Y-m-d", strtotime($thedate));
if($day == $thedate) {
... // your stuff
} else {
echo ('They do not match.');
}
There may be some minute differences in the way the string is encoded/stored. Since your $day variable was created with the date() function, you stand a better chance of matching them properly by doing the same with $thedate.
Upvotes: 1