web_master Posted May 31, 2008 Share Posted May 31, 2008 Hi, I want to print date of expiring, but: 1. when its 90 and more days until expire - the color of printed date is GREEN, 2. when its between 90-60 days until expire - the color of printed is #cc66ff, 3. when its 30 and less day until expire - the color of printed date is RED. Expire css is: .txt-expreg-3month { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; text-align: left; color: green; margin: 0px; } .txt-expreg-2month { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; text-align: left; color: #cc66ff; margin: 0px; } .txt-expreg-1month { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; text-align: left; color: red; margin: 0px; color: } Ive begin like this: <?php /* The expire day is an 8 digit nr: 20081010 -> $request['domain_expire'] But I have the date separated too in dbase: $request['domain_expreg_year'] $request['domain_expreg_month'] $request['domain_expreg_day'] */ $ninety_day = ($request['domain_expire'] - 300); $sixty_day = ($request['domain_expire'] - 200); $thirty = ($request['domain_expire'] - 100); if(date("Ymd") <= $ninety_day) { $expire_style = "txt-expreg-3month"; } if(date("Ymd") <= $sixty_day) { $expire_style = "txt-expreg-2month"; } if(date("Ymd") <= $thirty_day) { $expire_style = "txt-expreg-1month"; } print "<p class=\"".$expire_style."\">".$request['domain_expreg_year'].". ".$request['domain_expreg_month']." ".$request['domain_expreg_day'].".</p>"; ?> So, how can I do this? Thnx! Quote Link to comment https://forums.phpfreaks.com/topic/108122-solved-expire-date-with-diffeent-colors/ Share on other sites More sharing options...
kbh43dz_u Posted May 31, 2008 Share Posted May 31, 2008 Whats the problem? Maybe you could explain what's your problem more exactly.... Quote Link to comment https://forums.phpfreaks.com/topic/108122-solved-expire-date-with-diffeent-colors/#findComment-554184 Share on other sites More sharing options...
web_master Posted May 31, 2008 Author Share Posted May 31, 2008 Whats the problem? Example: Today is 20080531 Expire day is 20081231 20080531 < 20081231 BUT!!! its smaller than 20081131 (30 day minus), and its smaller than 20081031 (60 day minus) and its smaller than 20080931 (90 day minus) So, the color of font is allways RED I want to be a font color GREEN between date "today" to 90 day minus #cc66ff bewtween 90-60 day minus RED between 60-30 day minus and also RED between 30-0 day minus, but its not nessery. Quote Link to comment https://forums.phpfreaks.com/topic/108122-solved-expire-date-with-diffeent-colors/#findComment-554190 Share on other sites More sharing options...
wildteen88 Posted May 31, 2008 Share Posted May 31, 2008 Use if/elseif rather than seperate if's if(date("Ymd") <= $ninety_day) { $expire_style = "txt-expreg-3month"; } elseif(date("Ymd") <= $sixty_day) { $expire_style = "txt-expreg-2month"; } elseif(date("Ymd") <= $thirty_day) { $expire_style = "txt-expreg-1month"; } Quote Link to comment https://forums.phpfreaks.com/topic/108122-solved-expire-date-with-diffeent-colors/#findComment-554192 Share on other sites More sharing options...
kbh43dz_u Posted May 31, 2008 Share Posted May 31, 2008 simply turn it around.... edit: like "wildteen88" just told you *g* Quote Link to comment https://forums.phpfreaks.com/topic/108122-solved-expire-date-with-diffeent-colors/#findComment-554194 Share on other sites More sharing options...
Barand Posted May 31, 2008 Share Posted May 31, 2008 the date arithmetic is a little suspect <?php $date = 20080110; $ninetyday = $date - 300 ; // --> 20079810 ? ? ? ?> Quote Link to comment https://forums.phpfreaks.com/topic/108122-solved-expire-date-with-diffeent-colors/#findComment-554198 Share on other sites More sharing options...
web_master Posted May 31, 2008 Author Share Posted May 31, 2008 the date arithmetic is a little suspect <?php $date = 20080110; $ninetyday = $date - 300 ; // --> 20079810 ? ? ? ?> You right Barad... oh... than what is the solution? :'( Quote Link to comment https://forums.phpfreaks.com/topic/108122-solved-expire-date-with-diffeent-colors/#findComment-554204 Share on other sites More sharing options...
wildteen88 Posted May 31, 2008 Share Posted May 31, 2008 You might want to look into use strtotime or even mktime. eg: $thirty_days_ago = strtotime('-30 days); echo date('Y-m-d', $thirty_days_ago); Quote Link to comment https://forums.phpfreaks.com/topic/108122-solved-expire-date-with-diffeent-colors/#findComment-554210 Share on other sites More sharing options...
web_master Posted May 31, 2008 Author Share Posted May 31, 2008 You might want to look into use strtotime or even mktime. eg: $thirty_days_ago = strtotime('-30 days); echo date('Y-m-d', $thirty_days_ago); "strtotime" is a "server date", I need to divide 30, 60 or 90 day of date stored in dBase... Quote Link to comment https://forums.phpfreaks.com/topic/108122-solved-expire-date-with-diffeent-colors/#findComment-554221 Share on other sites More sharing options...
Barand Posted May 31, 2008 Share Posted May 31, 2008 <?php $date = 20080110; echo date ('Y-m-d', strtotime("$date -90 days")); // --> 2007-10-12 ?> Quote Link to comment https://forums.phpfreaks.com/topic/108122-solved-expire-date-with-diffeent-colors/#findComment-554227 Share on other sites More sharing options...
web_master Posted May 31, 2008 Author Share Posted May 31, 2008 hi, I hope I find the solution for my problem... I hope Im right... <?php // Expire colors $ninety_day = $request['domain_expire']; $sixty_day = $request['domain_expire']; $thirty_day = $request['domain_expire']; $ninety_day = date("Ymd", strtotime($ninety_day) - 7776000); $sixty_day = date("Ymd", strtotime($sixty_day) - 5184000); $thirty_day = date("Ymd", strtotime($thirty_day) - 2505600); if(date("Ymd") <= $ninety_day) { $expire_style = "txt-expreg-3month"; } elseif(date("Ymd") <= $sixty_day) { $expire_style = "txt-expreg-2month"; } elseif(date("Ymd") <= $thirty_day) { $expire_style = "txt-expreg-1month"; } else { $expire_style = "txt-expreg-1month"; } print "<p class=\"".$expire_style."\">".$request['domain_expreg_year'].". ".$domain_expreg_month." ".$request['domain_expreg_day'].".</p>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/108122-solved-expire-date-with-diffeent-colors/#findComment-554277 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.