Destramic Posted November 3, 2006 Share Posted November 3, 2006 i have a date from my mysql database DATE_FORMAT(date, '%d/%m/%y %r') AS date which formats: 03/11/06 10:19:26 AM but what i would like to do i check if the date is the same date as today.$date = $row['date']; echo $todays_date = gmdate("d/m/y");if ($todays_date == $date){ echo "Today [time]";} Link to comment https://forums.phpfreaks.com/topic/26043-timestamps/ Share on other sites More sharing options...
Orio Posted November 3, 2006 Share Posted November 3, 2006 Try using strtotime() -if (strtotime($todays_date) == strtotime($date))Orio. Link to comment https://forums.phpfreaks.com/topic/26043-timestamps/#findComment-119087 Share on other sites More sharing options...
Destramic Posted November 3, 2006 Author Share Posted November 3, 2006 nope sorry it didnt work..cause what im trying to do is if the pnews post date is the same as todays date i want it to display today and time.thanks Link to comment https://forums.phpfreaks.com/topic/26043-timestamps/#findComment-119147 Share on other sites More sharing options...
kenrbnsn Posted November 3, 2006 Share Posted November 3, 2006 Please post the script source between [b][nobbc][code][/code][/nobbc][/b] tags.Ken Link to comment https://forums.phpfreaks.com/topic/26043-timestamps/#findComment-119148 Share on other sites More sharing options...
alpine Posted November 3, 2006 Share Posted November 3, 2006 $compare_date is made to match the format of $todays_date since we cannot compare with hour-minute-seconds present.[code]<?php$date = $row['date'];$compare_date = date("d/m/y", strtotime($date));$todays_date = date("d/m/y");if ($todays_date == $compare_date){ echo "Is today";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/26043-timestamps/#findComment-119182 Share on other sites More sharing options...
Destramic Posted November 3, 2006 Author Share Posted November 3, 2006 [code]$query = "SELECT news_id, game_id, subject, DATE_FORMAT(date, '%d/%m/%y %r') AS date FROM news WHERE status = 'Active' ORDER BY news_id ASC LIMIT 5"; // Execute query$result = $mysqli->query($query);// Check query executionif ($result) { while ($row = $result->fetch_array()) { $news_id = $row['news_id']; $game_id = $row['game_id']; $subject = $row['subject']; $date = $row['date']; $todays_date = gmdate("d/m/y"); if ($todays_date == $date) { echo "Today [time]"; } echo "<img src='".$document_root."/images/game_icons/".$game_id.".gif' alt='' width='16' height='16' />\n"; echo "<a href='news.php#news_id=".$news_id."'><strong>".$subject."</strong></a> ".$date."\n"; } // Free result $result->close();}[/code] Link to comment https://forums.phpfreaks.com/topic/26043-timestamps/#findComment-119183 Share on other sites More sharing options...
alpine Posted November 3, 2006 Share Posted November 3, 2006 No offence - but if that was a hint on how to implement it into your code you could at least try it yourself first - as my wife once said to me: "You don't have to be a rocket to do that" ... Link to comment https://forums.phpfreaks.com/topic/26043-timestamps/#findComment-119199 Share on other sites More sharing options...
obsidian Posted November 3, 2006 Share Posted November 3, 2006 The way you are pulling your values, your $row['date'] value will [b]never[/b] match today's value since you're matching date and time to only date. You need to pull it apart one step further and only compare the [b]dates[/b] of each:[code]<?phplist($date, $time) = explode(' ', $row['date']);if ($date == date('m/d/y')) { // it occurred today echo "$time<br />\n";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/26043-timestamps/#findComment-119202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.