This topic is locked

Modifying how Date displays

8/24/2007 2:46:57 PM
PHPRunner General questions
paperhog author

[codebox]$str = "<table width=100% bgcolor=";

if ($value['job_post_date']>= now()-14)

$str.="white";

Else

$str.="pink";

$str.="><tr><td>".$value."</td></tr></table>";

$value=$str;

[/codebox]
This is the code I have tried but everything is pink!
Anything that is two weeks or older should be pink.
the job_post_date is stored as varchar 2007-07-01 Can someone please tell me what step I am missing? <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=6084&image=1&table=forumtopics' class='bbc_emoticon' alt=':blink:' />
TIA

L
larsonsc 8/24/2007

To the best of my knowledge, varchar dates (even when formatted the same as a regular date field) can not be used for date comparisons. I had to set all of my date fileds that I needed to make comparisons to a field type of date.

paperhog author 8/24/2007

To the best of my knowledge, varchar dates (even when formatted the same as a regular date field) can not be used for date comparisons. I had to set all of my date fileds that I needed to make comparisons to a field type of date.


I have always used the date field as varchar
So I could store it in YYYY-MM-DD format for easy adding and subtracting?
Is there a way to incorporate

SELECT CONVERT(VARCHAR(10), GETDATE(), 105) AS [YYYY-MM-DD] found this at http://www.sql-server-helper.com/tips/date-formats.aspx

J
Jane 8/27/2007

Lori,
try to use this code:

//current date - 14 days (14246060)

$curd = date("Y-m-d",strtotime(now())-14246060);

$str = "<table width=100% bgcolor=";

if ($value>= $curd)

$str.="white";

Else

$str.="pink";

$str.="><tr><td>".$value."</td></tr></table>";

$value=$str;

J
Jane 8/27/2007

Lori,
try to use this code:

//current date - 14 days (14246060)

$curd = date("Y-m-d",strtotime(now())-14246060);

$str = "<table width=100% bgcolor=";

if ($value>= $curd)

$str.="white";

Else

$str.="pink";

$str.="><tr><td>".$value."</td></tr></table>";

$value=$str;

paperhog author 8/27/2007

THANK YOU!
Works perfectly!
<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=20863&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />