Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi all

my question is about duo date

by reference of this thread

 

I read the MySQL's DATEDIFF(expr1,expr2) but still I dont know how it will be work.

 

Mr. pswason told to use SELECT DATEDIFF(expiration_date, CURDATE()) WHERE id=$id;

and he dont know about ... he says "I don't know if a card is considered expired if the expiration date is the current date"

I give the current date as not expiration date so I make my script as:

 

$tdy = date('Ymd');

in detail our many cards have expiry date like 19-08-2011, and we like to see how much days remaining by substract today date from.

my whole code is

 


<?php
$timezone = new DateTimeZone( "Asia/Riyadh" );
$date = new DateTime();
$date->setTimezone( $timezone );
echo  $today = $date->format( 'H:i:s A  /  D, M jS, Y' );
echo '<br />';

function datediff ($expri, $tdy)
{
$tdy = date('Ymd');
$tmr = (($expri - $tdy)/100*30); // $expri will be take from DB.
return $tmr;
}

$query = 'SELECT * FROM staff';
$result = mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC) )
{
       echo '<tr valign="top">';
       echo '<td>' . $row['id'] .
       		 '</td> <td>'. $row['name']			.
            '</td><td align="center">'			. $row['nationality'] .
            '</td><td align="center">'			. $row['card_no'];
            '</td><td align="center">';
$exdate = 'SELECT DATEDIFF(card_expiry_date, CURDATE())';// I dont know how to use mysql's condtions in php.
echo '</td><td align="center">'		. datediff($expri = $row['card_expiry_date'], $tdy);		
       echo '</tr>';


}
mysql_free_result($result);
mysql_close();
?>


Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
 Share

×
×
  • Create New...