Jump to content

plz help if u can..:)


tauchai83

Recommended Posts

i hav date problems. I have create a date that receive input $day, $month, $year separately from the user. (through drop down box).

Now i trying to get the expired date (appointment date) show up an "done" IMAGE. automatically by comparing with today's date. How should I do that? so far what i have coded work in reverse.

Here is my coding: what's wrong with it?

[color=blue]$bkdate = $Day."-".$Month."-".$Year;  (user input variable)
$today = date("d-m-Y"); (today date in format of 19-01-2007)

if($bkdate<$today )
{
echo "<td><img src=\"images/bullet.gif\" width=\"24\" height=\"24\" border=\"0\"></a></td>";
}[/color]

i try to use string compare function but it did not work as i want. who can help me? Thanks!! :)
Link to comment
Share on other sites

I find that comparing dates in this way do now work correctly because it's verifying strings, not dates

this will work:

[code]
<?php

$bkdate = "{$Year}-{$Month}-{$Day}";
$today = date("Y-m-d");

if(strtotime($bkdate)<strtotime($today) )
{
  // echo here
}
?>
[/code]

Dates are represented like string but to make calculations and comparings you should convert them in numbers.

php do not parse any string to find if it´s numeric or date or a boolean or anything else before comparing... you must parse (or convert) before making your test...
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.