Jump to content

PHP filter by Date


kool_samule

Recommended Posts

Hi Chaps,

 

I have a bit of PHP code, that at the moment doesn't work.

I'm trying to show all the 'overdue' projects in a different style:

 

     

<?php if ($row_rsProjects['projdue'] == '= DATE(NOW())') { ?>
      <tr class="overdue">
  <?php } else if ($row_rsProjects['projdue'] == '< DATE(NOW())') { ?>
      <tr class="duetoday">
  <?php } else { ?>
      <tr class="within">
  <?php }?>

 

The

'= DATE(NOW())'
works with MySQL, but I don't know how to get it to work with PHP. Any ideas?
Link to comment
https://forums.phpfreaks.com/topic/179976-php-filter-by-date/
Share on other sites

This is what I've got so far,

<?php

$today = date("dd/mm/yyyy");

if ($row_rsProjects['projdue_format'] == $today) { ?>

<tr class="duetoday">

<?php } else if ($row_rsProjects['projdue_format'] < $today) { ?>

<tr class="overdue">

<?php } else if ($row_rsProjects['projdue_format'] > $today) { ?>

<tr class="within">

<?php }?>

But still isn't working correctly, projects with today's date are showing up as 'overdue'

Link to comment
https://forums.phpfreaks.com/topic/179976-php-filter-by-date/#findComment-949460
Share on other sites

$today = date("dd/mm/yyyy");  gives the output  0202/1111/09090909 - you need to make sure you have your date format correct.

 

$today = date("Y-m-d"); will give you 2009-11-02 which is probably what you want to be compatable with mysql.

 

A much better way of doing this would be to use Unix timestamps that are integers. this makes > < and == much simpler.

 

Link to comment
https://forums.phpfreaks.com/topic/179976-php-filter-by-date/#findComment-949571
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.