Jump to content

timestamps


Destramic

Recommended Posts

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
Share on other sites

$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
Share on other sites

[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 execution
if ($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
Share on other sites

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]
<?php
list($date, $time) = explode(' ', $row['date']);
if ($date == date('m/d/y')) {
  // it occurred today
  echo "$time<br />\n";
}
?>
[/code]
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.