Jump to content

[SOLVED] Expire date with diffeent colors


web_master

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/108122-solved-expire-date-with-diffeent-colors/
Share on other sites

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.

 

 

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";
}

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

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>";
	?>

Archived

This topic is now archived and is closed to further replies.

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