This topic is locked
[SOLVED]

 Expiry date

9/20/2011 11:57:27 AM
PHPRunner General questions
W
wundebar author

Hi at all! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=17796&image=1&table=forumtopics' class='bbc_emoticon' alt=':)' />

I have a problem with the management of expiry dates.

I would like to colour of red all the expiry dates starting today ( so all the old dates until today) and give blue color for all the remaining dates. Searching into the forum i found this topic http://www.asprunner.com/forums/topic/3578-date-related-queries i've tried the solutions posted by jane in "view as" ad it work, but the problem is that i see, in the final output, the "datatime" field like is saved into mysql database! Maybe the problem is the function "now()", so i've tryed to formatting the dates with mktime() and date() always in the option custom of "view as" but without solving anything. Records are always in the format 2007-10-10 00:00:00, instead i would like the european format and without hours,minutes and seconds just something like this 10/10/2007.

Some idea or suggestion? I'm sorry for bad english!

Thanks for the help you'll give me.

Best Regards

C
cgphp 9/20/2011

There is a great article about conditional formatting here: http://xlinesoft.com/blog/2011/01/03/tutorial_conditional_formatting/
Anyway, to format a date use the date function as follow:

date("d/m/Y",strtotime(now()));
Sergey Kornilov admin 9/20/2011

As a first step you need to make sure your field in the database is able to accept datetime values.
If you use MySQL correct data type is DATETIME:

http://dev.mysql.com/doc/refman/5.5/en/datetime.html

W
wundebar author 9/22/2011



There is a great article about conditional formatting here: http://xlinesoft.com/blog/2011/01/03/tutorial_conditional_formatting/
Anyway, to format a date use the date function as follow:

date("d/m/Y",strtotime(now()));



Hi and thanks for answer me!

I've read the article about conditional formatting, and i've tried the first solution

if ($value < 0) {

$color="blue";

} else {

$color="red";

}

$value="<span style='color: " . $color . ";'>$value</span>";



but it not works, because it show me only blue records but not the red records.

So i've write this code:



if ($value<now())

{

$value = "<font color=red>".$value."</font>";

}

elseif($value>now())

{

$value = "<font color=blue>".$value."</font>";

}

and it works great! I have two colors, red for old dates and blu for records that are not expired yet, but the second problem isn't again solved <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=60978&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' /> i have again the "datetime" ( for admin, i have write bad last time) field like is saved into mysql database.

Cristian i would like to try your suggestion, but how? I have to create a variable and call it instead of now ()?

I'm sorry but i'm not very familiar with php, can you show me an example on my code?

Thank you so much!

C
cgphp 9/22/2011
if ($value<now())

{

$value = "<span style='color:red'>".date("d/m/Y",strtotime($value))."</span>";

}

elseif($value>now())

{

$value = "<span style='color:blue'>".date("d/m/Y",strtotime($value))."</span>";

}
W
wundebar author 9/23/2011


if ($value<now())

{

$value = "<span style='color:red'>".date("d/m/Y",strtotime($value))."</span>";

}

elseif($value>now())

{

$value = "<span style='color:blue'>".date("d/m/Y",strtotime($value))."</span>";

}



Hi Cristian!

It works great! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=61003&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' /> thank you very much!

Anyway.. i see that empty records are automatically filled with 01/01/1970 how can avoid this?

C
CK. 9/23/2011



Hi Cristian!

It works great! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=61005&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' /> thank you very much!

Anyway.. i see that empty records are automatically filled with 01/01/1970 how can avoid this?


The above condition show only $value > now() and $value < now(). How about the condition for $value == now()?
Base on your requirement,
if ($value<now()) {

$value = "<span style='color:red'>".date("d/m/Y",strtotime($value))."</span>";

} else {

$value = "<span style='color:blue'>".date("d/m/Y",strtotime($value))."</span>";

}
Than means whatever greater or equal to now() will turn red.
I'm not sure this one working not

$value = "<span style='color:".($value<now()? 'red': 'blue')."'>".date("d/m/Y",strtotime($value))."</span>";
Regards,

CK

C
cgphp 9/23/2011
if($value == "0000-00-00 00:00:00")

{

$value = "";

}

else

{

if ($value<now())

{

$value = "<span style='color:red'>".date("d/m/Y",strtotime($value))."</span>";

}

else

{

$value = "<span style='color:blue'>".date("d/m/Y",strtotime($value))."</span>";

}

}


Remove the elseif branch to evaluate the $value == now() condition.
The php.newbie solution is valid but not so inuitive and readable for a php beginner.

W
wundebar author 9/23/2011



The above condition show only $value > now() and $value < now(). How about the condition for $value == now()?
Base on your requirement,
if ($value<now()) {

$value = "<span style='color:red'>".date("d/m/Y",strtotime($value))."</span>";

} else {

$value = "<span style='color:blue'>".date("d/m/Y",strtotime($value))."</span>";

}
Than means whatever greater or equal to now() will turn red.
I'm not sure this one working not

$value = "<span style='color:".($value<now()? 'red': 'blue')."'>".date("d/m/Y",strtotime($value))."</span>";
Regards,

CK



Hi CK i've tried your solution, like this



if ($value<now()) {

$value = "<span style='color:red'>".date("d/m/Y",strtotime($value))."</span>";

} else {

$value = "<span style='color:blue'>".date("d/m/Y",strtotime($value))."</span>";

}

if (value==now())

{

$value = "<span style='color:".($value<now()? 'red': 'blue')."'>".date("d/m/Y",strtotime($value))."</span>";

}



but it not works.. but for sure i've written a wrong code <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=61008&image=1&table=forumreplies' class='bbc_emoticon' alt=':P' />


if($value == "0000-00-00 00:00:00")

{

$value = "";

}

else

{

if ($value<now())

{

$value = "<span style='color:red'>".date("d/m/Y",strtotime($value))."</span>";

}

else

{

$value = "<span style='color:blue'>".date("d/m/Y",strtotime($value))."</span>";

}

}


Remove the elseif branch to evaluate the $value == now() condition.
The php.newbie solution is valid but not so inuitive and readable for a php beginner.


Hi cristian, thanks a lot for your precious help!

I've copied and pasted your code right now but unfortunately the result it's the same it always show me red records for expired dates and blu records for dates who are not expired.. but there is again 01/01/1970 in red color. i'm so sad.. other suggestions? thank you!

C
cgphp 9/23/2011

Check in phpmyadmin the date values for empty record and let me know.

W
wundebar author 9/23/2011



Check in phpmyadmin the date values for empty record and let me know.


I see:

field name: scadenza personale

field type: datetime

field null: "yes"

field predefined: NULL
And nothing else.. i hope you mean this <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=61010&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

C
cgphp 9/23/2011

Not the structure but the data. Check the date field value for records where date was left empty.

W
wundebar author 9/23/2011



Not the structure but the data. Check the date field value for records where date was left empty.


Hi cristian, i understand what you mean, so i've changed your code like this



if($value == NULL)
{

$value = "";

}

else

{

if ($value<now())

{

$value = "<span style='color:red'>".date("d/m/Y",strtotime($value))."</span>";

}

else

{

$value = "<span style='color:blue'>".date("d/m/Y",strtotime($value))."</span>";

}

}


and with NULL it works! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=61013&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' /> i'm very happy <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=61013&image=2&table=forumreplies' class='bbc_emoticon' alt=':D' />

Thank you so much for all your support and help!

Have a good day!

bye bye <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=61013&image=3&table=forumreplies' class='bbc_emoticon' alt=';)' />