This topic is locked
[SOLVED]

 Change datefield of today into color

7/29/2011 2:09:26 PM
PHPRunner General questions
P
pim author

Hi there,
In my project there's a table with a field called 'StartDate'. I would like to change the view of this field, when the date is today. The background of the field should be yellow, or else the text should be for example red.
In a page on the forum I found the code as below (view as costumcode), but it changes the date into red, when the date is today and all past dates.
------------------------

if ($value<now())

{

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

}

------------------------
Could you help me out?
Thank you,
Pim

P
pim author 7/29/2011

Hi again,
Thank you for your link. I've looked at it, but it gives examples with fields that contain numbers. I really have no clue how to achieve this with a date field, with the condition that only today would be colored.
Could you help me out?

P
pim author 7/30/2011

I am still hoping that somebody could help me out on this.
I've tried several things, went through the forum, can color dates now in the past, in the future, depending on a value, but still not when only today should be colored.
Is there somebody who could help me here? Please?
Thank you!

C
cgphp 7/30/2011
if(strtotime($value) == strtotime(date("Y-m-d",time())))

{

blah blah blah

}
P
pim author 7/31/2011

Okay, so I guess to change color into red, I have to change your code into.
if(strtotime($value) == strtotime(date("Y-m-d",time())))

{

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

}
This didn't work. So I've left out the piece ,time(), because the field is a date field and not a date time field. This didn't work either.
Then I've deleted this code in the costum code, and added it to events before record updated. This doesn't work either. I'm getting crazy now. I'm stuck on this thing, because if I can't change the color of a date, then I can't work with this system. People will have to recognize a record immediately if it is today.
Even more, my next question would be that when this datefield should be green if it is tomorrow.
I've been writing html websites for a decade. and this seems to me like a simple question for php. Like adding metatags or alt tags or css to html. I just don't know where to put your code and what I have to do to adapt it.
I'm sorry to bother you again, but I do hope you like to assist on this further.
Thank you.

P
pim author 7/31/2011

Hi Christian,
You just offered me to help me out on this by making a payment. You told me it is hard to help me without seeing the files.
Well, I've tried to upload the project to the demo account, but by doing that, I get the message 'Incorrect Password' although it is the 1st time I tried the use the Demo account.
The whole project in this case is:
tablename [date],

field 1 [DateID] - INT

field 2 [Date] - DATE
In the past days I have been evaluating PHPRunner and was very happy with the quick support I received. I am evaluating this program because there are many PHP builders out there, and I just want to know I buy the right one.
So I am just honest, do you truly want to charge me for questions like these, or did you probably misunderstand my question before?
Please realize that I don't know if you're just a friendly guy out there who helps others with coding, or if you belong to costumer service.?

Sergey Kornilov admin 7/31/2011

Cristian,
is just a friendly guy who is trying to help other members.

C
cgphp 8/1/2011



Okay, so I guess to change color into red, I have to change your code into.
if(strtotime($value) == strtotime(date("Y-m-d",time())))

{

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

}
This didn't work. So I've left out the piece ,time(), because the field is a date field and not a date time field. This didn't work either.


It doens't matter if the field is a date field. The following statement

date("Y-m-d",time())



return only a date string.
So, if $value is a date, the if statement should work.
If you want a yellow background, paste the following code in the "List page: after record processed":



if(strtotime($data["field2"]) == strtotime(date("Y-m-d",time())))

$record["field2_style"].='style="background:yellow"';





I apologize for what happened. I try only to save your time.


Thanks

Cristian

P
pim author 8/1/2011

Hi,
Thank you so much for your answer. The code works now: the field gets yellow in list view if the field of the table is today.
I guess I may have been struggling as well because I tried to add the code to a query (view). This doesn't work apparently, although I do not understand why. (?)
Thank you very much Cristian for your help. I'm situated on a very remote location and I appreciate it very much that you help me out.

It's a relieve to know that somebody takes the time for doing that.
<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=59875&image=1&table=forumreplies' class='bbc_emoticon' alt=';)' /> Pim