tauchai83 Posted January 19, 2007 Share Posted January 19, 2007 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!! :) Quote Link to comment Share on other sites More sharing options...
cicibo Posted January 19, 2007 Share Posted January 19, 2007 u can try separate those date for month,day n yearthis is just a logic error... Quote Link to comment Share on other sites More sharing options...
paul2463 Posted January 19, 2007 Share Posted January 19, 2007 you input date is not correct it should look like[code]<?php$bkdate = "$Day-$Month-$Year"; //(user input variable)>?[/code] Quote Link to comment Share on other sites More sharing options...
eric1235711 Posted January 19, 2007 Share Posted January 19, 2007 I find that comparing dates in this way do now work correctly because it's verifying strings, not datesthis 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... Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 19, 2007 Share Posted January 19, 2007 Eric's version is close.Instead of getting a timestamp, converting to date, then back to time, just do $bkdate = $Year.'-'.$Month.'-'.$Day;if(strtotime($bkdate)<time()){} Quote Link to comment Share on other sites More sharing options...
tauchai83 Posted January 20, 2007 Author Share Posted January 20, 2007 it's a great help from u all....it works...hehe...thanks a lot! now i learn a new function called strtotime. Thanks!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.