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