chocolate Posted June 19, 2008 Share Posted June 19, 2008 Hi, I am so freaking new to PHP... I want to create a code in which I state the date. And based on that date I can show a CODEWORD, or image on future dates. So, let's say the date is 06-19-2008, now... if its +1 day it will echo this if its +2 days it will echo this if its +3 days it will echo this...... and so on. This is what I came up with, but can't seem to make it work... $startdate = '06/19/2007'; if ($newdate == date('m/d/Y', strtotime("+1 days", strtotime($startdate)))) echo "first<br>"; if ($newdate == date('m/d/Y', strtotime("+2 days", strtotime($startdate)))) echo "second<br>"; if ($newdate == date('m/d/Y', strtotime("+3 days", strtotime($startdate)))) echo "third<br>"; it doesn't work... it just writes all the dates... -=( I need this to show one code per day from a starting date. Thanks P.S. in the past, I did this: but it sux because I have to change the dates all the time I need a new one. $today = date("m-d-Y"); if ($today == date("05-16-2008")) { $video1 = 343KOSLL31';} if ($today == date("05-17-2008")) { $video1 = '5MK78hZL3o0';} if ($today == date("05-18-2008")) { $video1 = '5xNZ5CC0gvk';} if ($today == date("05-19-2008")) { $video1 = '3q2vZDQU8aA';} if ($today == date("05-20-2008")) { $video1 = 'BfWIP02g41g';} if ($today == date("05-21-2008")) { $video1 = 'lawXkvPFRgI';} HEEEEEEEEEEEELP... anyone??? ??? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted June 19, 2008 Share Posted June 19, 2008 Not sure what you're trying to accomplish...why wouldn't you just generate the code based off of the current date and then you wouldn't have to update it constantly? Why do you need a start date to base future values off of? Quote Link to comment Share on other sites More sharing options...
timmah1 Posted June 19, 2008 Share Posted June 19, 2008 Try this $startdate = '06/19/2007'; if ($newdate == date('m/d/Y', strtotime("+1 days", strtotime($startdate)))) { echo "first }"; elseif ($newdate == date('m/d/Y', strtotime("+2 days", strtotime($startdate)))) { echo "second }"; elseif ($newdate == date('m/d/Y', strtotime("+3 days", strtotime($startdate)))) { echo "third }"; Quote Link to comment Share on other sites More sharing options...
chocolate Posted June 19, 2008 Author Share Posted June 19, 2008 Nah... its not working. any other suggestions.... I really appreciate it. Quote Link to comment Share on other sites More sharing options...
chocolate Posted June 19, 2008 Author Share Posted June 19, 2008 if I can do it without a starting date... how would I be able to accomplish it? How would it know what code to pull based on the date? For example... it has to start let's say today 06/19/2008 and today it will show the code "FIRST" then tomorrow (+1 day) should show "SECOND" and so on... how can I pull it off without a starting date? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted June 19, 2008 Share Posted June 19, 2008 Will today's date always have the code "FIRST"? Or does the code for today change every day? Quote Link to comment Share on other sites More sharing options...
chocolate Posted June 19, 2008 Author Share Posted June 19, 2008 well the first date will have a code. then the next day will have the second code and the day after that will have the third code and so on... so each day will have a different code Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted June 19, 2008 Share Posted June 19, 2008 always the same code for each relative day though? Today will always have the same code. When tomorrow is today, it will have the same code as today, and the day after tomorrow will have the same code as tomorrow when tomorrow is today (whew...that's confusing). <?php $today = 'abc'; $tomorrow = 'def'; $day_after_that = 'ghi'; echo 'Today is: ' . date("Y-m-d") . ' and the code is: ' . $today; echo 'Tomorrow is ' . date("Y-m-d", mktime(null, null, null, date("m"), date("d") + 1, date("Y"))) . ' and the code is ' . $tomorrow; echo 'The day after tomorrow is ' . date("Y-m-d", mktime(null, null, null, date("m"), date("d") + 2, date("Y"))) . ' and the code is ' . $day_after_that; Quote Link to comment Share on other sites More sharing options...
phpSensei Posted June 19, 2008 Share Posted June 19, 2008 Use a Mysql Database and store the previous dates. Quote Link to comment Share on other sites More sharing options...
chocolate Posted June 19, 2008 Author Share Posted June 19, 2008 well... I guess I need to explain better what I want to accomplish. This is what I have done in the past: <? $today = date("m-d-Y"); if ($today == date("06-19-2008")) echo "THE CODE FOR TODAY IS RED"; if ($today == date("06-20-2008")) echo "THE CODE FOR TODAY IS BLUE"; if ($today == date("06-21-2008")) echo "THE CODE FOR TODAY IS GREEN"; ?> As you can see, it gives me a different code depending on the date - RED for the June 19 - BLUE for June 20 - Green for June 21 Now, the problem I have with this is that themore codes I have, the more I have to update the dates manually. So I have always insert 06-22-2008, 06-23-2008 and so on..... So I want to get rid of all that manual work and have a script that already knows that its the NEXT DAY. So it starts today - CODE RED When it realizes that its one day after it will give me CODE BLUE and then a day after that will give me GREEN.... Makes sense? I need to show only one code per day,... but each code is different.... and it needs to know what code was given the day before. Quote Link to comment 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.